Skip to content

Commit

Permalink
Merge pull request #4227 from rouault/cppcheck_fixes
Browse files Browse the repository at this point in the history
Fix very minor issues or workaround latest cppcheck false positives
  • Loading branch information
rouault authored Aug 15, 2024
2 parents de10157 + c0a18c3 commit 8cf1baf
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/apps/gie.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ static int process_file(const char *fname) {
}
if (F->level == 0)
return errmsg(-3, "File '%s':Missing '<gie>' cmnd - bye!\n", fname);
if (F->level && F->level % 2) {
if (F->level % 2) {
if (F->strict_mode)
return errmsg(-4, "File '%s':Missing '</gie-strict>' cmnd - bye!\n",
fname);
Expand Down
17 changes: 8 additions & 9 deletions src/apps/proj_strtod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<char *>(p);
return HUGE_VAL;
}
} else
p++;
} else if (!(isdigit(*p))) {
if (endptr)
*endptr = const_cast<char *>(p);
return HUGE_VAL;
}

/* Go on and read the exponent */
n = 0;
Expand Down
10 changes: 8 additions & 2 deletions src/iso19111/c_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}
Expand Down
17 changes: 7 additions & 10 deletions src/iso19111/crs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -2077,7 +2077,6 @@ static bool exportAsWKT1CompoundCRSWithEllipsoidalHeight(
base2DCRS->_exportToWKT(formatter);
vertCRS->_exportToWKT(formatter);
formatter->endNode();
return true;
}
//! @endcond

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions src/iso19111/metadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -928,8 +928,8 @@ void Identifier::Private::setProperties(
AUTHORITY_KEY);
}
} else {
if (auto citation =
dynamic_cast<const Citation *>(pVal->get())) {
auto citation = dynamic_cast<const Citation *>(pVal->get());
if (citation) {
authority_ = *citation;
} else {
throw InvalidValueTypeException("Invalid value type for " +
Expand Down
7 changes: 3 additions & 4 deletions src/iso19111/operation/coordinateoperationfactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1655,10 +1655,9 @@ filterAndSort(const std::vector<CoordinateOperationNNPtr> &sourceList,
logTrace("number of results before filter and sort: " +
toString(static_cast<int>(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<int>(resFiltered.size())));
Expand Down
1 change: 1 addition & 0 deletions src/projections/vandg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/quadtree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,8 @@ template <class Feature> class QuadTree {
}
#endif

void search(const Node &node, double x, double y,
std::vector<Feature> &features) const {
static void search(const Node &node, double x, double y,
std::vector<Feature> &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))
Expand Down
1 change: 1 addition & 0 deletions src/transformations/gridshift.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 8cf1baf

Please sign in to comment.