aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEven Rouault <even.rouault@spatialys.com>2021-09-05 15:41:40 +0200
committerGitHub <noreply@github.com>2021-09-05 15:41:40 +0200
commit71b372e6f08b2f40fbd043c80b56bdb8d2c0b5a0 (patch)
treeeaae225629ae6101db6094b046f319df4f6aba7a
parent09367628bfe698d6a73a1b928bcf611ea675103d (diff)
parentb91af0075a7e8a189e2cd443a823a0798e0b9ed9 (diff)
downloadPROJ-71b372e6f08b2f40fbd043c80b56bdb8d2c0b5a0.tar.gz
PROJ-71b372e6f08b2f40fbd043c80b56bdb8d2c0b5a0.zip
Merge pull request #2841 from rouault/cppcheck_fixes
Cppcheck fixes
-rw-r--r--src/apps/proj.cpp3
-rw-r--r--src/conversions/cart.cpp6
-rw-r--r--src/conversions/unitconvert.cpp6
-rw-r--r--src/fwd.cpp30
-rw-r--r--src/internal.cpp20
-rw-r--r--src/inv.cpp30
-rw-r--r--src/iso19111/crs.cpp14
-rw-r--r--src/iso19111/io.cpp127
-rw-r--r--src/iso19111/operation/conversion.cpp9
-rw-r--r--src/pipeline.cpp10
-rw-r--r--src/projections/healpix.cpp2
-rw-r--r--src/transformations/helmert.cpp12
-rw-r--r--src/transformations/molodensky.cpp12
13 files changed, 161 insertions, 120 deletions
diff --git a/src/apps/proj.cpp b/src/apps/proj.cpp
index 93f1ce7b..6368ef2c 100644
--- a/src/apps/proj.cpp
+++ b/src/apps/proj.cpp
@@ -115,7 +115,8 @@ static void process(FILE *fid) {
facs_bad = proj_errno(Proj);
}
- data.xy = (*proj.fwd)(data.lp, Proj);
+ const auto xy = (*proj.fwd)(data.lp, Proj);
+ data.xy = xy;
if (dofactors && inverse) {
facs = proj_factors(Proj, coord);
diff --git a/src/conversions/cart.cpp b/src/conversions/cart.cpp
index 5175599a..a134bc6a 100644
--- a/src/conversions/cart.cpp
+++ b/src/conversions/cart.cpp
@@ -212,7 +212,8 @@ static PJ_XY cart_forward (PJ_LP lp, PJ *P) {
point.lp = lp;
point.lpz.z = 0;
- point.xyz = cartesian (point.lpz, P);
+ const auto xyz = cartesian (point.lpz, P);
+ point.xyz = xyz;
return point.xy;
}
@@ -222,7 +223,8 @@ static PJ_LP cart_reverse (PJ_XY xy, PJ *P) {
point.xy = xy;
point.xyz.z = 0;
- point.lpz = geodetic (point.xyz, P);
+ const auto lpz = geodetic (point.xyz, P);
+ point.lpz = lpz;
return point.lp;
}
diff --git a/src/conversions/unitconvert.cpp b/src/conversions/unitconvert.cpp
index 187acf17..d584d93f 100644
--- a/src/conversions/unitconvert.cpp
+++ b/src/conversions/unitconvert.cpp
@@ -322,7 +322,8 @@ static PJ_XYZ forward_3d(PJ_LPZ lpz, PJ *P) {
point.lpz = lpz;
/* take care of the horizontal components in the 2D function */
- point.xy = forward_2d(point.lp, P);
+ const auto xy = forward_2d(point.lp, P);
+ point.xy = xy;
point.xyz.z *= Q->z_factor;
@@ -339,7 +340,8 @@ static PJ_LPZ reverse_3d(PJ_XYZ xyz, PJ *P) {
point.xyz = xyz;
/* take care of the horizontal components in the 2D function */
- point.lp = reverse_2d(point.xy, P);
+ const auto lp = reverse_2d(point.xy, P);
+ point.lp = lp;
point.xyz.z /= Q->z_factor;
diff --git a/src/fwd.cpp b/src/fwd.cpp
index 8583a6e7..c267dfca 100644
--- a/src/fwd.cpp
+++ b/src/fwd.cpp
@@ -193,9 +193,15 @@ PJ_XY pj_fwd(PJ_LP lp, PJ *P) {
/* Do the transformation, using the lowest dimensional transformer available */
if (P->fwd)
- coo.xy = P->fwd(coo.lp, P);
+ {
+ const auto xy = P->fwd(coo.lp, P);
+ coo.xy = xy;
+ }
else if (P->fwd3d)
- coo.xyz = P->fwd3d (coo.lpz, P);
+ {
+ const auto xyz = P->fwd3d (coo.lpz, P);
+ coo.xyz = xyz;
+ }
else if (P->fwd4d)
coo = P->fwd4d (coo, P);
else {
@@ -227,11 +233,17 @@ PJ_XYZ pj_fwd3d(PJ_LPZ lpz, PJ *P) {
/* Do the transformation, using the lowest dimensional transformer feasible */
if (P->fwd3d)
- coo.xyz = P->fwd3d(coo.lpz, P);
+ {
+ const auto xyz = P->fwd3d(coo.lpz, P);
+ coo.xyz = xyz;
+ }
else if (P->fwd4d)
coo = P->fwd4d (coo, P);
else if (P->fwd)
- coo.xy = P->fwd (coo.lp, P);
+ {
+ const auto xy = P->fwd (coo.lp, P);
+ coo.xy = xy;
+ }
else {
proj_errno_set (P, PROJ_ERR_OTHER_NO_INVERSE_OP);
return proj_coord_error ().xyz;
@@ -261,9 +273,15 @@ PJ_COORD pj_fwd4d (PJ_COORD coo, PJ *P) {
if (P->fwd4d)
coo = P->fwd4d (coo, P);
else if (P->fwd3d)
- coo.xyz = P->fwd3d (coo.lpz, P);
+ {
+ const auto xyz = P->fwd3d (coo.lpz, P);
+ coo.xyz = xyz;
+ }
else if (P->fwd)
- coo.xy = P->fwd (coo.lp, P);
+ {
+ const auto xy = P->fwd (coo.lp, P);
+ coo.xy = xy;
+ }
else {
proj_errno_set (P, PROJ_ERR_OTHER_NO_INVERSE_OP);
return proj_coord_error ();
diff --git a/src/internal.cpp b/src/internal.cpp
index b96e2160..e934069f 100644
--- a/src/internal.cpp
+++ b/src/internal.cpp
@@ -83,11 +83,17 @@ chained calls starting out with a call to its 2D interface.
direction = static_cast<PJ_DIRECTION>(-direction);
switch (direction) {
case PJ_FWD:
- coo.xy = pj_fwd (coo.lp, P);
+ {
+ const auto xy = pj_fwd (coo.lp, P);
+ coo.xy = xy;
return coo;
+ }
case PJ_INV:
- coo.lp = pj_inv (coo.xy, P);
+ {
+ const auto lp = pj_inv (coo.xy, P);
+ coo.lp = lp;
return coo;
+ }
case PJ_IDENT:
break;
}
@@ -110,11 +116,17 @@ chained calls starting out with a call to its 3D interface.
direction = static_cast<PJ_DIRECTION>(-direction);
switch (direction) {
case PJ_FWD:
- coo.xyz = pj_fwd3d (coo.lpz, P);
+ {
+ const auto xyz = pj_fwd3d (coo.lpz, P);
+ coo.xyz = xyz;
return coo;
+ }
case PJ_INV:
- coo.lpz = pj_inv3d (coo.xyz, P);
+ {
+ const auto lpz = pj_inv3d (coo.xyz, P);
+ coo.lpz = lpz;
return coo;
+ }
case PJ_IDENT:
break;
}
diff --git a/src/inv.cpp b/src/inv.cpp
index 8925f0e9..92b3c1d6 100644
--- a/src/inv.cpp
+++ b/src/inv.cpp
@@ -151,9 +151,15 @@ PJ_LP pj_inv(PJ_XY xy, PJ *P) {
/* Do the transformation, using the lowest dimensional transformer available */
if (P->inv)
- coo.lp = P->inv(coo.xy, P);
+ {
+ const auto lp = P->inv(coo.xy, P);
+ coo.lp = lp;
+ }
else if (P->inv3d)
- coo.lpz = P->inv3d (coo.xyz, P);
+ {
+ const auto lpz = P->inv3d (coo.xyz, P);
+ coo.lpz = lpz;
+ }
else if (P->inv4d)
coo = P->inv4d (coo, P);
else {
@@ -185,11 +191,17 @@ PJ_LPZ pj_inv3d (PJ_XYZ xyz, PJ *P) {
/* Do the transformation, using the lowest dimensional transformer feasible */
if (P->inv3d)
- coo.lpz = P->inv3d (coo.xyz, P);
+ {
+ const auto lpz = P->inv3d (coo.xyz, P);
+ coo.lpz = lpz;
+ }
else if (P->inv4d)
coo = P->inv4d (coo, P);
else if (P->inv)
- coo.lp = P->inv (coo.xy, P);
+ {
+ const auto lp = P->inv (coo.xy, P);
+ coo.lp = lp;
+ }
else {
proj_errno_set (P, PROJ_ERR_OTHER_NO_INVERSE_OP);
return proj_coord_error ().lpz;
@@ -219,9 +231,15 @@ PJ_COORD pj_inv4d (PJ_COORD coo, PJ *P) {
if (P->inv4d)
coo = P->inv4d (coo, P);
else if (P->inv3d)
- coo.lpz = P->inv3d (coo.xyz, P);
+ {
+ const auto lpz = P->inv3d (coo.xyz, P);
+ coo.lpz = lpz;
+ }
else if (P->inv)
- coo.lp = P->inv (coo.xy, P);
+ {
+ const auto lp = P->inv (coo.xy, P);
+ coo.lp = lp;
+ }
else {
proj_errno_set (P, PROJ_ERR_OTHER_NO_INVERSE_OP);
return proj_coord_error ();
diff --git a/src/iso19111/crs.cpp b/src/iso19111/crs.cpp
index a15758ab..7c8fcd81 100644
--- a/src/iso19111/crs.cpp
+++ b/src/iso19111/crs.cpp
@@ -2274,6 +2274,7 @@ GeodeticCRS::identify(const io::AuthorityFactoryPtr &authorityFactory) const {
auto searchByDatumCode =
[this, &authorityFactory, &res, &geodetic_crs_type, crsCriterion,
&dbContext](const common::IdentifiedObjectNNPtr &l_datum) {
+ bool resModified = false;
for (const auto &id : l_datum->identifiers()) {
try {
auto tempRes =
@@ -2284,11 +2285,13 @@ GeodeticCRS::identify(const io::AuthorityFactoryPtr &authorityFactory) const {
if (_isEquivalentTo(crs.get(), crsCriterion,
dbContext)) {
res.emplace_back(crs, 70);
+ resModified = true;
}
}
} catch (const std::exception &) {
}
}
+ return resModified;
};
auto searchByEllipsoid = [this, &authorityFactory, &res, &thisDatum,
@@ -2331,8 +2334,8 @@ GeodeticCRS::identify(const io::AuthorityFactoryPtr &authorityFactory) const {
}
};
- const auto searchByDatumOrEllipsoid = [&authorityFactory, &res,
- &thisDatum, searchByDatumCode,
+ const auto searchByDatumOrEllipsoid = [&authorityFactory, &thisDatum,
+ searchByDatumCode,
searchByEllipsoid]() {
if (!thisDatum->identifiers().empty()) {
searchByDatumCode(thisDatum);
@@ -2342,11 +2345,12 @@ GeodeticCRS::identify(const io::AuthorityFactoryPtr &authorityFactory) const {
{io::AuthorityFactory::ObjectType::
GEODETIC_REFERENCE_FRAME},
false);
- const size_t sizeBefore = res.size();
+ bool resModified = false;
for (const auto &candidateDatum : candidateDatums) {
- searchByDatumCode(candidateDatum);
+ if (searchByDatumCode(candidateDatum))
+ resModified = true;
}
- if (sizeBefore == res.size()) {
+ if (!resModified) {
searchByEllipsoid();
}
}
diff --git a/src/iso19111/io.cpp b/src/iso19111/io.cpp
index 161441ee..a1b06ae7 100644
--- a/src/iso19111/io.cpp
+++ b/src/iso19111/io.cpp
@@ -6773,65 +6773,61 @@ static BaseObjectNNPtr createFromUserInput(const std::string &text,
const auto searchObject =
[&factory](
const std::string &objectName, bool approximateMatch,
- const std::vector<AuthorityFactory::ObjectType> &objectTypes,
- bool &goOn) {
- constexpr size_t limitResultCount = 10;
- auto res = factory->createObjectsFromName(
- objectName, objectTypes, approximateMatch,
- limitResultCount);
- if (res.size() == 1) {
- return res.front();
- }
- if (res.size() > 1) {
- if (objectTypes.size() == 1 &&
- objectTypes[0] == AuthorityFactory::ObjectType::CRS) {
- for (size_t ndim = 2; ndim <= 3; ndim++) {
- for (const auto &obj : res) {
- auto crs = dynamic_cast<crs::GeographicCRS *>(
- obj.get());
- if (crs && crs->coordinateSystem()
- ->axisList()
- .size() == ndim) {
- return obj;
- }
+ const std::vector<AuthorityFactory::ObjectType> &objectTypes)
+ -> IdentifiedObjectPtr {
+ constexpr size_t limitResultCount = 10;
+ auto res = factory->createObjectsFromName(
+ objectName, objectTypes, approximateMatch, limitResultCount);
+ if (res.size() == 1) {
+ return res.front().as_nullable();
+ }
+ if (res.size() > 1) {
+ if (objectTypes.size() == 1 &&
+ objectTypes[0] == AuthorityFactory::ObjectType::CRS) {
+ for (size_t ndim = 2; ndim <= 3; ndim++) {
+ for (const auto &obj : res) {
+ auto crs =
+ dynamic_cast<crs::GeographicCRS *>(obj.get());
+ if (crs &&
+ crs->coordinateSystem()->axisList().size() ==
+ ndim) {
+ return obj.as_nullable();
}
}
}
+ }
- std::string msg("several objects matching this name: ");
- bool first = true;
- for (const auto &obj : res) {
- if (msg.size() > 200) {
- msg += ", ...";
- break;
- }
- if (!first) {
- msg += ", ";
- }
- first = false;
- msg += obj->nameStr();
+ std::string msg("several objects matching this name: ");
+ bool first = true;
+ for (const auto &obj : res) {
+ if (msg.size() > 200) {
+ msg += ", ...";
+ break;
}
- throw ParsingException(msg);
+ if (!first) {
+ msg += ", ";
+ }
+ first = false;
+ msg += obj->nameStr();
}
- goOn = true;
- throw ParsingException("dummy");
- };
+ throw ParsingException(msg);
+ }
+ return nullptr;
+ };
const auto searchCRS = [&searchObject](const std::string &objectName) {
- bool goOn = false;
const auto objectTypes = std::vector<AuthorityFactory::ObjectType>{
AuthorityFactory::ObjectType::CRS};
- try {
+ {
constexpr bool approximateMatch = false;
- return searchObject(objectName, approximateMatch, objectTypes,
- goOn);
- } catch (const std::exception &) {
- if (!goOn)
- throw;
+ auto ret =
+ searchObject(objectName, approximateMatch, objectTypes);
+ if (ret)
+ return ret;
}
+
constexpr bool approximateMatch = true;
- return searchObject(objectName, approximateMatch, objectTypes,
- goOn);
+ return searchObject(objectName, approximateMatch, objectTypes);
};
// strings like "WGS 84 + EGM96 height"
@@ -6841,8 +6837,8 @@ static BaseObjectNNPtr createFromUserInput(const std::string &text,
if (tokensCompound.size() == 2) {
auto obj1 = searchCRS(tokensCompound[0]);
auto obj2 = searchCRS(tokensCompound[1]);
- auto crs1 = util::nn_dynamic_pointer_cast<CRS>(obj1);
- auto crs2 = util::nn_dynamic_pointer_cast<CRS>(obj2);
+ auto crs1 = std::dynamic_pointer_cast<CRS>(obj1);
+ auto crs2 = std::dynamic_pointer_cast<CRS>(obj2);
if (crs1 && crs2) {
compoundCRS =
CompoundCRS::create(
@@ -6862,28 +6858,19 @@ static BaseObjectNNPtr createFromUserInput(const std::string &text,
// Fourth pass: approximate match on other objects
for (int pass = 0; pass <= 3; ++pass) {
const bool approximateMatch = (pass >= 2);
- bool goOn = false;
- try {
- return searchObject(
- text, approximateMatch,
- (pass == 0 || pass == 2)
- ? std::vector<
- AuthorityFactory::ObjectType>{AuthorityFactory::
- ObjectType::CRS}
- : std::vector<
- AuthorityFactory::
- ObjectType>{AuthorityFactory::ObjectType::
- ELLIPSOID,
- AuthorityFactory::ObjectType::
- DATUM,
- AuthorityFactory::ObjectType::
- DATUM_ENSEMBLE,
- AuthorityFactory::ObjectType::
- COORDINATE_OPERATION},
- goOn);
- } catch (const std::exception &) {
- if (!goOn)
- throw;
+ auto ret = searchObject(
+ text, approximateMatch,
+ (pass == 0 || pass == 2)
+ ? std::vector<
+ AuthorityFactory::ObjectType>{AuthorityFactory::
+ ObjectType::CRS}
+ : std::vector<AuthorityFactory::ObjectType>{
+ AuthorityFactory::ObjectType::ELLIPSOID,
+ AuthorityFactory::ObjectType::DATUM,
+ AuthorityFactory::ObjectType::DATUM_ENSEMBLE,
+ AuthorityFactory::ObjectType::COORDINATE_OPERATION});
+ if (ret) {
+ return NN_NO_CHECK(ret);
}
if (compoundCRS) {
return NN_NO_CHECK(compoundCRS);
diff --git a/src/iso19111/operation/conversion.cpp b/src/iso19111/operation/conversion.cpp
index 3cc452f8..3d09c9fa 100644
--- a/src/iso19111/operation/conversion.cpp
+++ b/src/iso19111/operation/conversion.cpp
@@ -2359,12 +2359,11 @@ ConversionNNPtr Conversion::createAxisOrderReversal(bool is3D) {
createMethodMapNameEPSGCode(
EPSG_CODE_METHOD_AXIS_ORDER_REVERSAL_3D),
{}, {});
- } else {
- return create(createMapNameEPSGCode(AXIS_ORDER_CHANGE_2D_NAME, 15498),
- createMethodMapNameEPSGCode(
- EPSG_CODE_METHOD_AXIS_ORDER_REVERSAL_2D),
- {}, {});
}
+ return create(
+ createMapNameEPSGCode(AXIS_ORDER_CHANGE_2D_NAME, 15498),
+ createMethodMapNameEPSGCode(EPSG_CODE_METHOD_AXIS_ORDER_REVERSAL_2D),
+ {}, {});
}
// ---------------------------------------------------------------------------
diff --git a/src/pipeline.cpp b/src/pipeline.cpp
index 74ab2488..c001ba27 100644
--- a/src/pipeline.cpp
+++ b/src/pipeline.cpp
@@ -566,11 +566,6 @@ PJ *OPERATION(pipeline,0) {
pj->left = right_pj_left;
pj->right = right_pj_left;
}
- else if (right_pj_right != PJ_IO_UNITS_WHATEVER)
- {
- pj->left = right_pj_right;
- pj->right = right_pj_right;
- }
}
}
@@ -585,11 +580,6 @@ PJ *OPERATION(pipeline,0) {
pj->left = left_pj_right;
pj->right = left_pj_right;
}
- else if (left_pj_left != PJ_IO_UNITS_WHATEVER)
- {
- pj->left = left_pj_left;
- pj->right = left_pj_left;
- }
}
}
diff --git a/src/projections/healpix.cpp b/src/projections/healpix.cpp
index 6f34f9f0..3aa22807 100644
--- a/src/projections/healpix.cpp
+++ b/src/projections/healpix.cpp
@@ -416,7 +416,7 @@ static CapMap get_cap(double x, double y, int north_square, int south_square,
} else {
capmap.cn = north_square;
}
- } else if (capmap.region == CapMap::south) {
+ } else /* if (capmap.region == CapMap::south) */ {
if (y <= x + M_FORTPI + EPS && y > -x - 5*M_FORTPI + EPS) {
capmap.cn = (south_square + 1) % 4;
} else if (y < x + M_FORTPI - EPS && y <= -x - 5*M_FORTPI + EPS) {
diff --git a/src/transformations/helmert.cpp b/src/transformations/helmert.cpp
index f9bb45e0..253dc2f6 100644
--- a/src/transformations/helmert.cpp
+++ b/src/transformations/helmert.cpp
@@ -369,7 +369,8 @@ static PJ_XYZ helmert_forward_3d (PJ_LPZ lpz, PJ *P) {
point.lpz = lpz;
if (Q->fourparam) {
- point.xy = helmert_forward(point.lp, P);
+ const auto xy = helmert_forward(point.lp, P);
+ point.xy = xy;
return point.xyz;
}
@@ -409,7 +410,8 @@ static PJ_LPZ helmert_reverse_3d (PJ_XYZ xyz, PJ *P) {
point.xyz = xyz;
if (Q->fourparam) {
- point.lp = helmert_reverse(point.xy, P);
+ const auto lp = helmert_reverse(point.xy, P);
+ point.lp = lp;
return point.lpz;
}
@@ -448,7 +450,8 @@ static PJ_COORD helmert_forward_4d (PJ_COORD point, PJ *P) {
build_rot_matrix(P);
}
- point.xyz = helmert_forward_3d (point.lpz, P);
+ const auto xyz = helmert_forward_3d (point.lpz, P);
+ point.xyz = xyz;
return point;
}
@@ -466,7 +469,8 @@ static PJ_COORD helmert_reverse_4d (PJ_COORD point, PJ *P) {
build_rot_matrix(P);
}
- point.lpz = helmert_reverse_3d (point.xyz, P);
+ const auto lpz = helmert_reverse_3d (point.xyz, P);
+ point.lpz = lpz;
return point;
}
diff --git a/src/transformations/molodensky.cpp b/src/transformations/molodensky.cpp
index 29c51b55..3901fce9 100644
--- a/src/transformations/molodensky.cpp
+++ b/src/transformations/molodensky.cpp
@@ -215,7 +215,8 @@ static PJ_XY forward_2d(PJ_LP lp, PJ *P) {
PJ_COORD point = {{0,0,0,0}};
point.lp = lp;
- point.xyz = forward_3d(point.lpz, P);
+ const auto xyz = forward_3d(point.lpz, P);
+ point.xyz = xyz;
return point.xy;
}
@@ -226,7 +227,8 @@ static PJ_LP reverse_2d(PJ_XY xy, PJ *P) {
point.xy = xy;
point.xyz.z = 0;
- point.lpz = reverse_3d(point.xyz, P);
+ const auto lpz = reverse_3d(point.xyz, P);
+ point.lpz = lpz;
return point.lp;
}
@@ -259,7 +261,8 @@ static PJ_XYZ forward_3d(PJ_LPZ lpz, PJ *P) {
static PJ_COORD forward_4d(PJ_COORD obs, PJ *P) {
- obs.xyz = forward_3d(obs.lpz, P);
+ const auto xyz = forward_3d(obs.lpz, P);
+ obs.xyz = xyz;
return obs;
}
@@ -291,7 +294,8 @@ static PJ_LPZ reverse_3d(PJ_XYZ xyz, PJ *P) {
static PJ_COORD reverse_4d(PJ_COORD obs, PJ *P) {
- obs.lpz = reverse_3d(obs.xyz, P);
+ const auto lpz = reverse_3d(obs.xyz, P);
+ obs.lpz = lpz;
return obs;
}