Skip to content

Commit 54918d7

Browse files
committed
Coverity Scan fixes
1 parent 84d1a09 commit 54918d7

File tree

17 files changed

+122
-100
lines changed

17 files changed

+122
-100
lines changed

src/apps/projinfo.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ static void outputObject(
488488
std::cout << std::endl;
489489
}
490490

491-
const auto projStringExportable =
491+
auto projStringExportable =
492492
nn_dynamic_pointer_cast<IPROJStringExportable>(obj);
493493
bool alreadyOutputted = false;
494494
if (projStringExportable) {
@@ -511,7 +511,7 @@ static void outputObject(
511511
dbContext, allowUseIntermediateCRS));
512512
}
513513
if (!objToExport) {
514-
objToExport = projStringExportable;
514+
objToExport = std::move(projStringExportable);
515515
}
516516

517517
auto formatter = PROJStringFormatter::create(
@@ -1103,7 +1103,7 @@ int main(int argc, char **argv) {
11031103
bool listCRSSpecified = false;
11041104

11051105
for (int i = 1; i < argc; i++) {
1106-
const std::string arg(argv[i]);
1106+
std::string arg(argv[i]);
11071107
if (arg == "-o" && i + 1 < argc) {
11081108
outputSwitchSpecified = true;
11091109
i++;
@@ -1424,7 +1424,7 @@ int main(int argc, char **argv) {
14241424
std::cerr << "Unrecognized option: " << arg << std::endl;
14251425
usage();
14261426
} else {
1427-
positional_args.push_back(arg);
1427+
positional_args.push_back(std::move(arg));
14281428
}
14291429
}
14301430

src/apps/projsync.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,10 @@ static std::vector<double> get_bbox(const json &j) {
9090
} else {
9191
for (const auto &obj : j) {
9292
if (obj.is_array()) {
93-
const auto subres = get_bbox(obj);
93+
auto subres = get_bbox(obj);
9494
if (subres.size() == 4) {
9595
if (res.empty()) {
96-
res = subres;
96+
res = std::move(subres);
9797
} else {
9898
res[0] = std::min(res[0], subres[0]);
9999
res[1] = std::min(res[1], subres[1]);
@@ -492,13 +492,13 @@ int main(int argc, char *argv[]) {
492492
bool foundPlus180 = false;
493493
for (const auto &obj : j_coordinates) {
494494
if (obj.is_array()) {
495-
const auto tmp = get_bbox(obj);
495+
auto tmp = get_bbox(obj);
496496
if (tmp.size() == 4) {
497497
if (tmp[0] == -180)
498498
foundMinus180 = true;
499499
else if (tmp[2] == 180)
500500
foundPlus180 = true;
501-
grid_bboxes.push_back(tmp);
501+
grid_bboxes.push_back(std::move(tmp));
502502
}
503503
}
504504
}
@@ -565,11 +565,11 @@ int main(int argc, char *argv[]) {
565565
continue;
566566
}
567567

568-
const std::string resource_url(
568+
std::string resource_url(
569569
std::string(endpoint).append("/").append(name));
570570
if (proj_is_download_needed(ctx, resource_url.c_str(), false)) {
571571
total_size_to_download += file_size;
572-
to_download.push_back(resource_url);
572+
to_download.push_back(std::move(resource_url));
573573
} else {
574574
if (!quiet) {
575575
std::cout << resource_url << " already downloaded."

src/ell_set.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,8 @@ static int ellps_ellps(PJ *P) {
178178
PJ empty_PJ;
179179
pj_inherit_ellipsoid_def(&empty_PJ, P);
180180
}
181-
ellps_size(P);
182-
ellps_shape(P);
181+
if (ellps_size(P) || ellps_shape(P))
182+
return proj_errno_set(P, PROJ_ERR_OTHER /*ENOMEM*/);
183183

184184
P->params = old_params;
185185
free(new_params->next);
@@ -328,6 +328,7 @@ static int ellps_shape(PJ *P) {
328328
}
329329
if (P->b == P->a)
330330
break;
331+
// coverity[division_by_zero]
331332
P->f = (P->a - P->b) / P->a;
332333
P->es = 2 * P->f - P->f * P->f;
333334
break;
@@ -641,6 +642,12 @@ int pj_ell_set(PJ_CONTEXT *ctx, paralist *pl, double *a, double *es) {
641642
B.params = pl;
642643

643644
ret = pj_ellipsoid(&B);
645+
646+
free(B.def_size);
647+
free(B.def_shape);
648+
free(B.def_spherification);
649+
free(B.def_ellps);
650+
644651
if (ret)
645652
return ret;
646653

src/filemanager.cpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1721,28 +1721,27 @@ std::vector<std::string> pj_get_default_searchpaths(PJ_CONTEXT *ctx) {
17211721
ret.push_back(proj_context_get_user_writable_directory(ctx, false));
17221722
}
17231723

1724-
const std::string envPROJ_DATA =
1725-
NS_PROJ::FileManager::getProjDataEnvVar(ctx);
1726-
const std::string relativeSharedProj = pj_get_relative_share_proj(ctx);
1724+
std::string envPROJ_DATA = NS_PROJ::FileManager::getProjDataEnvVar(ctx);
1725+
std::string relativeSharedProj = pj_get_relative_share_proj(ctx);
17271726

17281727
if (gbPROJ_DATA_ENV_VAR_TRIED_LAST) {
17291728
/* Situation where PROJ_DATA environment variable is tried in last */
17301729
#ifdef PROJ_DATA
17311730
ret.push_back(PROJ_DATA);
17321731
#endif
17331732
if (!relativeSharedProj.empty()) {
1734-
ret.push_back(relativeSharedProj);
1733+
ret.push_back(std::move(relativeSharedProj));
17351734
}
17361735
if (!envPROJ_DATA.empty()) {
1737-
ret.push_back(envPROJ_DATA);
1736+
ret.push_back(std::move(envPROJ_DATA));
17381737
}
17391738
} else {
17401739
/* Situation where PROJ_DATA environment variable is used if defined */
17411740
if (!envPROJ_DATA.empty()) {
1742-
ret.push_back(envPROJ_DATA);
1741+
ret.push_back(std::move(envPROJ_DATA));
17431742
} else {
17441743
if (!relativeSharedProj.empty()) {
1745-
ret.push_back(relativeSharedProj);
1744+
ret.push_back(std::move(relativeSharedProj));
17461745
}
17471746
#ifdef PROJ_DATA
17481747
ret.push_back(PROJ_DATA);
@@ -1802,7 +1801,7 @@ NS_PROJ::FileManager::open_resource_file(PJ_CONTEXT *ctx, const char *name,
18021801
auto dbContext = getDBcontext(ctx);
18031802
if (dbContext) {
18041803
try {
1805-
const auto filename = dbContext->getProjGridName(name);
1804+
auto filename = dbContext->getProjGridName(name);
18061805
if (!filename.empty()) {
18071806
file.reset(reinterpret_cast<NS_PROJ::File *>(
18081807
pj_open_lib_internal(ctx, filename.c_str(), "rb",
@@ -1814,7 +1813,7 @@ NS_PROJ::FileManager::open_resource_file(PJ_CONTEXT *ctx, const char *name,
18141813
} else {
18151814
// For final network access attempt, use the new
18161815
// name.
1817-
tmpString = filename;
1816+
tmpString = std::move(filename);
18181817
name = tmpString.c_str();
18191818
}
18201819
}
@@ -2020,10 +2019,9 @@ void pj_load_ini(PJ_CONTEXT *ctx) {
20202019
const auto equal = content.find('=', pos);
20212020
if (equal < eol) {
20222021
const auto key = trim(content.substr(pos, equal - pos));
2023-
const auto value =
2024-
trim(content.substr(equal + 1, eol - (equal + 1)));
2022+
auto value = trim(content.substr(equal + 1, eol - (equal + 1)));
20252023
if (ctx->endpoint.empty() && key == "cdn_endpoint") {
2026-
ctx->endpoint = value;
2024+
ctx->endpoint = std::move(value);
20272025
} else if (proj_network == nullptr && key == "network") {
20282026
ctx->networking.enabled = ci_equal(value, "ON") ||
20292027
ci_equal(value, "YES") ||

src/iso19111/c_api.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2980,11 +2980,11 @@ proj_get_crs_info_list_from_database(PJ_CONTEXT *ctx, const char *auth_name,
29802980
int i = 0;
29812981
try {
29822982
auto dbContext = getDBcontext(ctx);
2983-
const std::string authName = auth_name ? auth_name : "";
2983+
std::string authName = auth_name ? auth_name : "";
29842984
auto actualAuthNames =
29852985
dbContext->getVersionedAuthoritiesFromName(authName);
29862986
if (actualAuthNames.empty())
2987-
actualAuthNames.push_back(authName);
2987+
actualAuthNames.push_back(std::move(authName));
29882988
std::list<AuthorityFactory::CRSInfo> concatList;
29892989
for (const auto &actualAuthName : actualAuthNames) {
29902990
auto factory = AuthorityFactory::create(dbContext, actualAuthName);

src/iso19111/coordinatesystem.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,8 @@ void CoordinateSystemAxis::_exportToWKT(io::WKTFormatter *formatter, int order,
391391
formatter->startNode(io::WKTConstants::AXIS, !identifiers().empty());
392392
const std::string &axisName = nameStr();
393393
const std::string &abbrev = abbreviation();
394-
const std::string parenthesizedAbbrev = "(" + abbrev + ")";
394+
std::string parenthesizedAbbrev =
395+
std::string("(").append(abbrev).append(")");
395396
std::string dir = direction().toString();
396397
std::string axisDesignation;
397398

@@ -436,14 +437,14 @@ void CoordinateSystemAxis::_exportToWKT(io::WKTFormatter *formatter, int order,
436437
if (direction() == AxisDirection::GEOCENTRIC_X ||
437438
direction() == AxisDirection::GEOCENTRIC_Y ||
438439
direction() == AxisDirection::GEOCENTRIC_Z) {
439-
axisDesignation = parenthesizedAbbrev;
440+
axisDesignation = std::move(parenthesizedAbbrev);
440441
}
441442
// For cartesian CS with Easting/Northing, export only the abbreviation
442443
else if ((order == 1 && axisName == AxisName::Easting &&
443444
abbrev == AxisAbbreviation::E) ||
444445
(order == 2 && axisName == AxisName::Northing &&
445446
abbrev == AxisAbbreviation::N)) {
446-
axisDesignation = parenthesizedAbbrev;
447+
axisDesignation = std::move(parenthesizedAbbrev);
447448
}
448449
}
449450
formatter->addQuotedString(axisDesignation);

src/iso19111/datum.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,7 @@ double Ellipsoid::computedInverseFlattening() PROJ_PURE_DEFN {
743743
*/
744744
double Ellipsoid::squaredEccentricity() PROJ_PURE_DEFN {
745745
const double rf = computedInverseFlattening();
746+
// coverity[divide_by_zero]
746747
const double f = rf != 0.0 ? 1. / rf : 0.0;
747748
const double e2 = f * (2 - f);
748749
return e2;

src/iso19111/factory.cpp

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3609,7 +3609,7 @@ DatabaseContext::getAliasFromOfficialName(const std::string &officialName,
36093609
std::list<std::string> l;
36103610
l.emplace_back(res2.front()[0]);
36113611
l.emplace_back((*(std::next(res2.begin())))[0]);
3612-
const auto uniqueEsriAlias = getUniqueEsriAlias(l);
3612+
std::string uniqueEsriAlias = getUniqueEsriAlias(l);
36133613
if (!uniqueEsriAlias.empty())
36143614
return uniqueEsriAlias;
36153615
}
@@ -5691,14 +5691,14 @@ AuthorityFactory::Private::createProjectedCRSEnd(const std::string &code,
56915691
pj_add_type_crs_if_needed(text_definition), context());
56925692
auto projCRS = dynamic_cast<const crs::ProjectedCRS *>(obj.get());
56935693
if (projCRS) {
5694-
const auto conv = projCRS->derivingConversion();
5694+
auto conv = projCRS->derivingConversion();
56955695
auto newConv =
56965696
(conv->nameStr() == "unnamed")
56975697
? operation::Conversion::create(
56985698
util::PropertyMap().set(
56995699
common::IdentifiedObject::NAME_KEY, name),
57005700
conv->method(), conv->parameterValues())
5701-
: conv;
5701+
: std::move(conv);
57025702
auto crsRet = crs::ProjectedCRS::create(
57035703
props, projCRS->baseCRS(), newConv,
57045704
projCRS->coordinateSystem());
@@ -6632,12 +6632,12 @@ operation::CoordinateOperationNNPtr AuthorityFactory::createCoordinateOperation(
66326632
std::string());
66336633
if (step_direction == "forward") {
66346634
++countExplicitDirection;
6635-
operations.push_back(stepOp);
6635+
operations.push_back(std::move(stepOp));
66366636
} else if (step_direction == "reverse") {
66376637
++countExplicitDirection;
66386638
operations.push_back(stepOp->inverse());
66396639
} else {
6640-
operations.push_back(stepOp);
6640+
operations.push_back(std::move(stepOp));
66416641
}
66426642
}
66436643

@@ -7364,7 +7364,7 @@ AuthorityFactory::createFromCRSCodesWithIntermediates(
73647364
"FROM coordinate_operation_view v1 "
73657365
"JOIN coordinate_operation_view v2 ");
73667366

7367-
const std::string joinSupersession(
7367+
const char *joinSupersession =
73687368
"LEFT JOIN supersession ss1 ON "
73697369
"ss1.superseded_table_name = v1.table_name AND "
73707370
"ss1.superseded_auth_name = v1.auth_name AND "
@@ -7376,23 +7376,23 @@ AuthorityFactory::createFromCRSCodesWithIntermediates(
73767376
"ss2.superseded_auth_name = v2.auth_name AND "
73777377
"ss2.superseded_code = v2.code AND "
73787378
"ss2.superseded_table_name = ss2.replacement_table_name AND "
7379-
"ss2.same_source_target_crs = 1 ");
7379+
"ss2.same_source_target_crs = 1 ";
73807380
const std::string joinArea(
7381-
(discardSuperseded ? joinSupersession : std::string()) +
7382-
"JOIN usage u1 ON "
7383-
"u1.object_table_name = v1.table_name AND "
7384-
"u1.object_auth_name = v1.auth_name AND "
7385-
"u1.object_code = v1.code "
7386-
"JOIN extent a1 "
7387-
"ON a1.auth_name = u1.extent_auth_name AND "
7388-
"a1.code = u1.extent_code "
7389-
"JOIN usage u2 ON "
7390-
"u2.object_table_name = v2.table_name AND "
7391-
"u2.object_auth_name = v2.auth_name AND "
7392-
"u2.object_code = v2.code "
7393-
"JOIN extent a2 "
7394-
"ON a2.auth_name = u2.extent_auth_name AND "
7395-
"a2.code = u2.extent_code ");
7381+
(discardSuperseded ? std::string(joinSupersession) : std::string())
7382+
.append("JOIN usage u1 ON "
7383+
"u1.object_table_name = v1.table_name AND "
7384+
"u1.object_auth_name = v1.auth_name AND "
7385+
"u1.object_code = v1.code "
7386+
"JOIN extent a1 "
7387+
"ON a1.auth_name = u1.extent_auth_name AND "
7388+
"a1.code = u1.extent_code "
7389+
"JOIN usage u2 ON "
7390+
"u2.object_table_name = v2.table_name AND "
7391+
"u2.object_auth_name = v2.auth_name AND "
7392+
"u2.object_code = v2.code "
7393+
"JOIN extent a2 "
7394+
"ON a2.auth_name = u2.extent_auth_name AND "
7395+
"a2.code = u2.extent_code "));
73967396
const std::string orderBy(
73977397
"ORDER BY (CASE WHEN accuracy1 is NULL THEN 1 ELSE 0 END) + "
73987398
"(CASE WHEN accuracy2 is NULL THEN 1 ELSE 0 END), "
@@ -9247,12 +9247,12 @@ AuthorityFactory::createObjectsFromNameEx(
92479247

92489248
const auto &auth_name = row[1];
92499249
const auto &code = row[2];
9250-
const auto key =
9250+
auto key =
92519251
std::pair<std::string, std::string>(auth_name, code);
92529252
if (setIdentified.find(key) != setIdentified.end()) {
92539253
continue;
92549254
}
9255-
setIdentified.insert(key);
9255+
setIdentified.insert(std::move(key));
92569256
auto factory = d->createFactory(auth_name);
92579257
res.emplace_back(PairObjectName(
92589258
factory->createGeodeticDatum(code), name));

src/iso19111/io.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7367,7 +7367,7 @@ static CRSNNPtr importFromWMSAUTO(const std::string &text) {
73677367
throw ParsingException("invalid WMS AUTO CRS definition");
73687368
}
73697369

7370-
const auto getConversion = [=]() {
7370+
const auto getConversion = [dfRefLong, dfRefLat, &parts]() {
73717371
const int nProjId = std::stoi(parts[0]);
73727372
switch (nProjId) {
73737373
case 42001: // Auto UTM
@@ -7410,7 +7410,7 @@ static CRSNNPtr importFromWMSAUTO(const std::string &text) {
74107410
}
74117411
};
74127412

7413-
const auto getUnits = [=]() -> const UnitOfMeasure & {
7413+
const auto getUnits = [nUnitsId]() -> const UnitOfMeasure & {
74147414
switch (nUnitsId) {
74157415
case 9001:
74167416
return UnitOfMeasure::METRE;
@@ -9965,16 +9965,16 @@ PROJStringSyntaxParser(const std::string &projString, std::vector<Step> &steps,
99659965
title = word.substr(strlen("title="));
99669966
} else if (word != "step") {
99679967
const auto pos = word.find('=');
9968-
auto key = word.substr(0, pos);
9968+
const auto key = word.substr(0, pos);
99699969

9970-
const Step::KeyValue pair(
9970+
Step::KeyValue pair(
99719971
(pos != std::string::npos)
99729972
? Step::KeyValue(key, word.substr(pos + 1))
99739973
: Step::KeyValue(key));
99749974
if (steps.empty()) {
9975-
globalParamValues.push_back(pair);
9975+
globalParamValues.push_back(std::move(pair));
99769976
} else {
9977-
steps.back().paramValues.push_back(pair);
9977+
steps.back().paramValues.push_back(std::move(pair));
99789978
}
99799979
}
99809980
}
@@ -11227,7 +11227,7 @@ PROJStringParser::Private::processAxisSwap(Step &step,
1122711227
? Meridian::create(Angle(0, UnitOfMeasure::DEGREE)).as_nullable()
1122811228
: nullMeridian);
1122911229

11230-
const CoordinateSystemAxisNNPtr west =
11230+
CoordinateSystemAxisNNPtr west =
1123111231
createAxis(isSpherical ? "Planetocentric longitude"
1123211232
: isGeographic ? AxisName::Longitude
1123311233
: AxisName::Westing,
@@ -11236,7 +11236,7 @@ PROJStringParser::Private::processAxisSwap(Step &step,
1123611236
: std::string(),
1123711237
AxisDirection::WEST, unit);
1123811238

11239-
const CoordinateSystemAxisNNPtr south =
11239+
CoordinateSystemAxisNNPtr south =
1124011240
createAxis(isSpherical ? "Planetocentric latitude"
1124111241
: isGeographic ? AxisName::Latitude
1124211242
: AxisName::Southing,
@@ -11292,8 +11292,8 @@ PROJStringParser::Private::processAxisSwap(Step &step,
1129211292
}
1129311293
} else if ((step.name == "krovak" || step.name == "mod_krovak") &&
1129411294
hasParamValue(step, "czech")) {
11295-
axis[0] = west;
11296-
axis[1] = south;
11295+
axis[0] = std::move(west);
11296+
axis[1] = std::move(south);
1129711297
}
1129811298
return axis;
1129911299
}

0 commit comments

Comments
 (0)