From c0a18c38551669d0a6e52bfaa742b5f7b5d05cc8 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Thu, 15 Aug 2024 16:26:28 +0200 Subject: [PATCH] Fix very minor issues or workaround latest cppcheck false positives --- src/apps/gie.cpp | 2 +- src/apps/proj_strtod.cpp | 17 ++++++++--------- src/iso19111/c_api.cpp | 10 ++++++++-- src/iso19111/crs.cpp | 17 +++++++---------- src/iso19111/metadata.cpp | 4 ++-- .../operation/coordinateoperationfactory.cpp | 7 +++---- src/projections/vandg.cpp | 1 + src/quadtree.hpp | 4 ++-- src/transformations/gridshift.cpp | 1 + 9 files changed, 33 insertions(+), 30 deletions(-) diff --git a/src/apps/gie.cpp b/src/apps/gie.cpp index f77e697d7e..390b015fd0 100644 --- a/src/apps/gie.cpp +++ b/src/apps/gie.cpp @@ -460,7 +460,7 @@ static int process_file(const char *fname) { } if (F->level == 0) return errmsg(-3, "File '%s':Missing '' cmnd - bye!\n", fname); - if (F->level && F->level % 2) { + if (F->level % 2) { if (F->strict_mode) return errmsg(-4, "File '%s':Missing '' cmnd - bye!\n", fname); diff --git a/src/apps/proj_strtod.cpp b/src/apps/proj_strtod.cpp index 3a0e81f696..e7d9b577c1 100644 --- a/src/apps/proj_strtod.cpp +++ b/src/apps/proj_strtod.cpp @@ -271,18 +271,17 @@ double proj_strtod(const char *str, char **endptr) { p++; /* Does it have a sign? */ sign = 0; - if ('-' == *p) + if ('-' == *p) { sign = -1; - if ('+' == *p) + p++; + } else if ('+' == *p) { sign = +1; - if (0 == sign) { - if (!(isdigit(*p) || *p == '_')) { - if (endptr) - *endptr = const_cast(p); - return HUGE_VAL; - } - } else p++; + } else if (!(isdigit(*p))) { + if (endptr) + *endptr = const_cast(p); + return HUGE_VAL; + } /* Go on and read the exponent */ n = 0; diff --git a/src/iso19111/c_api.cpp b/src/iso19111/c_api.cpp index b558a11750..7ed33afa14 100644 --- a/src/iso19111/c_api.cpp +++ b/src/iso19111/c_api.cpp @@ -9529,11 +9529,13 @@ PROJ_STRING_LIST proj_get_insert_statements( (void)options; struct TempSessionHolder { + private: PJ_CONTEXT *m_ctx; - PJ_INSERT_SESSION *m_tempSession = nullptr; + PJ_INSERT_SESSION *m_tempSession; TempSessionHolder(const TempSessionHolder &) = delete; TempSessionHolder &operator=(const TempSessionHolder &) = delete; + public: TempSessionHolder(PJ_CONTEXT *ctx, PJ_INSERT_SESSION *session) : m_ctx(ctx), m_tempSession(session ? nullptr @@ -9544,12 +9546,16 @@ PROJ_STRING_LIST proj_get_insert_statements( proj_insert_object_session_destroy(m_ctx, m_tempSession); } } + + inline PJ_INSERT_SESSION *GetTempSession() const { + return m_tempSession; + } }; try { TempSessionHolder oHolder(ctx, session); if (!session) { - session = oHolder.m_tempSession; + session = oHolder.GetTempSession(); if (!session) { return nullptr; } diff --git a/src/iso19111/crs.cpp b/src/iso19111/crs.cpp index c7014f97b1..df606a41c4 100644 --- a/src/iso19111/crs.cpp +++ b/src/iso19111/crs.cpp @@ -2056,7 +2056,7 @@ static bool exportAsESRIWktCompoundCRSWithEllipsoidalHeight( // Try to format a Geographic/ProjectedCRS 3D CRS as a // GEOGCS[]/PROJCS[],VERTCS["Ellipsoid (metre)",DATUM["Ellipsoid",2002],...] -static bool exportAsWKT1CompoundCRSWithEllipsoidalHeight( +static void exportAsWKT1CompoundCRSWithEllipsoidalHeight( const CRSNNPtr &base2DCRS, const cs::CoordinateSystemAxisNNPtr &verticalAxis, io::WKTFormatter *formatter) { @@ -2077,7 +2077,6 @@ static bool exportAsWKT1CompoundCRSWithEllipsoidalHeight( base2DCRS->_exportToWKT(formatter); vertCRS->_exportToWKT(formatter); formatter->endNode(); - return true; } //! @endcond @@ -2154,10 +2153,9 @@ void GeodeticCRS::_exportToWKT(io::WKTFormatter *formatter) const { } if (formatter->isAllowedEllipsoidalHeightAsVerticalCRS()) { - if (exportAsWKT1CompoundCRSWithEllipsoidalHeight( - geogCRS2D, axisList[2], formatter)) { - return; - } + exportAsWKT1CompoundCRSWithEllipsoidalHeight(geogCRS2D, axisList[2], + formatter); + return; } io::FormattingException::Throw( @@ -4248,10 +4246,9 @@ void ProjectedCRS::_exportToWKT(io::WKTFormatter *formatter) const { if (!formatter->useESRIDialect() && formatter->isAllowedEllipsoidalHeightAsVerticalCRS()) { - if (exportAsWKT1CompoundCRSWithEllipsoidalHeight( - projCRS2D, axisList[2], formatter)) { - return; - } + exportAsWKT1CompoundCRSWithEllipsoidalHeight(projCRS2D, axisList[2], + formatter); + return; } io::FormattingException::Throw( diff --git a/src/iso19111/metadata.cpp b/src/iso19111/metadata.cpp index 6aa4c9a025..148cad191e 100644 --- a/src/iso19111/metadata.cpp +++ b/src/iso19111/metadata.cpp @@ -928,8 +928,8 @@ void Identifier::Private::setProperties( AUTHORITY_KEY); } } else { - if (auto citation = - dynamic_cast(pVal->get())) { + auto citation = dynamic_cast(pVal->get()); + if (citation) { authority_ = *citation; } else { throw InvalidValueTypeException("Invalid value type for " + diff --git a/src/iso19111/operation/coordinateoperationfactory.cpp b/src/iso19111/operation/coordinateoperationfactory.cpp index a5385cf504..c6a3dbcbb8 100644 --- a/src/iso19111/operation/coordinateoperationfactory.cpp +++ b/src/iso19111/operation/coordinateoperationfactory.cpp @@ -1655,10 +1655,9 @@ filterAndSort(const std::vector &sourceList, logTrace("number of results before filter and sort: " + toString(static_cast(sourceList.size()))); #endif - auto resFiltered = - FilterResults(sourceList, context, extent1, extent2, false) - .andSort() - .getRes(); + FilterResults filterResults(sourceList, context, extent1, extent2, false); + filterResults.andSort(); + const auto &resFiltered = filterResults.getRes(); #ifdef TRACE_CREATE_OPERATIONS logTrace("number of results after filter and sort: " + toString(static_cast(resFiltered.size()))); diff --git a/src/projections/vandg.cpp b/src/projections/vandg.cpp index 3a3afebf89..7ddd336228 100644 --- a/src/projections/vandg.cpp +++ b/src/projections/vandg.cpp @@ -50,6 +50,7 @@ static PJ_XY vandg_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ // https://github.com/OSGeo/PROJ/issues/1906#issuecomment-583168348 // The choice of p2 is completely arbitrary. volatile double p2_tmp = p2; + // cppcheck-suppress redundantAssignment p2 = p2_tmp; } xy.x = g - p2; // G - P^2 diff --git a/src/quadtree.hpp b/src/quadtree.hpp index 6c67b30ee9..fccf354ee5 100644 --- a/src/quadtree.hpp +++ b/src/quadtree.hpp @@ -227,8 +227,8 @@ template class QuadTree { } #endif - void search(const Node &node, double x, double y, - std::vector &features) const { + static void search(const Node &node, double x, double y, + std::vector &features) { // Does this node overlap the area of interest at all? If not, // return without adding to the list at all. if (!node.rect.contains(x, y)) diff --git a/src/transformations/gridshift.cpp b/src/transformations/gridshift.cpp index ab1470b842..fc516b1150 100644 --- a/src/transformations/gridshift.cpp +++ b/src/transformations/gridshift.cpp @@ -372,6 +372,7 @@ PJ_XYZ gridshiftData::grid_interpolate(PJ_CONTEXT *ctx, const std::string &type, gridInfo.idxSampleXYZ[2] = idxSampleZ; iterCache = m_cacheGridInfo.emplace(grid, std::move(gridInfo)).first; } + // cppcheck-suppress derefInvalidIteratorRedundantCheck GridInfo &gridInfo = iterCache->second; const int idxSampleX = gridInfo.idxSampleX; const int idxSampleY = gridInfo.idxSampleY;