Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coverity Scan fixes #4377

Merged
merged 1 commit into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/apps/projinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ static void outputObject(
std::cout << std::endl;
}

const auto projStringExportable =
auto projStringExportable =
nn_dynamic_pointer_cast<IPROJStringExportable>(obj);
bool alreadyOutputted = false;
if (projStringExportable) {
Expand All @@ -511,7 +511,7 @@ static void outputObject(
dbContext, allowUseIntermediateCRS));
}
if (!objToExport) {
objToExport = projStringExportable;
objToExport = std::move(projStringExportable);
}

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

for (int i = 1; i < argc; i++) {
const std::string arg(argv[i]);
std::string arg(argv[i]);
if (arg == "-o" && i + 1 < argc) {
outputSwitchSpecified = true;
i++;
Expand Down Expand Up @@ -1424,7 +1424,7 @@ int main(int argc, char **argv) {
std::cerr << "Unrecognized option: " << arg << std::endl;
usage();
} else {
positional_args.push_back(arg);
positional_args.push_back(std::move(arg));
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/apps/projsync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ static std::vector<double> get_bbox(const json &j) {
} else {
for (const auto &obj : j) {
if (obj.is_array()) {
const auto subres = get_bbox(obj);
auto subres = get_bbox(obj);
if (subres.size() == 4) {
if (res.empty()) {
res = subres;
res = std::move(subres);
} else {
res[0] = std::min(res[0], subres[0]);
res[1] = std::min(res[1], subres[1]);
Expand Down Expand Up @@ -492,13 +492,13 @@ int main(int argc, char *argv[]) {
bool foundPlus180 = false;
for (const auto &obj : j_coordinates) {
if (obj.is_array()) {
const auto tmp = get_bbox(obj);
auto tmp = get_bbox(obj);
if (tmp.size() == 4) {
if (tmp[0] == -180)
foundMinus180 = true;
else if (tmp[2] == 180)
foundPlus180 = true;
grid_bboxes.push_back(tmp);
grid_bboxes.push_back(std::move(tmp));
}
}
}
Expand Down Expand Up @@ -565,11 +565,11 @@ int main(int argc, char *argv[]) {
continue;
}

const std::string resource_url(
std::string resource_url(
std::string(endpoint).append("/").append(name));
if (proj_is_download_needed(ctx, resource_url.c_str(), false)) {
total_size_to_download += file_size;
to_download.push_back(resource_url);
to_download.push_back(std::move(resource_url));
} else {
if (!quiet) {
std::cout << resource_url << " already downloaded."
Expand Down
11 changes: 9 additions & 2 deletions src/ell_set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ static int ellps_ellps(PJ *P) {
PJ empty_PJ;
pj_inherit_ellipsoid_def(&empty_PJ, P);
}
ellps_size(P);
ellps_shape(P);
if (ellps_size(P) || ellps_shape(P))
return proj_errno_set(P, PROJ_ERR_OTHER /*ENOMEM*/);

P->params = old_params;
free(new_params->next);
Expand Down Expand Up @@ -328,6 +328,7 @@ static int ellps_shape(PJ *P) {
}
if (P->b == P->a)
break;
// coverity[division_by_zero]
P->f = (P->a - P->b) / P->a;
P->es = 2 * P->f - P->f * P->f;
break;
Expand Down Expand Up @@ -641,6 +642,12 @@ int pj_ell_set(PJ_CONTEXT *ctx, paralist *pl, double *a, double *es) {
B.params = pl;

ret = pj_ellipsoid(&B);

free(B.def_size);
free(B.def_shape);
free(B.def_spherification);
free(B.def_ellps);

if (ret)
return ret;

Expand Down
22 changes: 10 additions & 12 deletions src/filemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1721,28 +1721,27 @@ std::vector<std::string> pj_get_default_searchpaths(PJ_CONTEXT *ctx) {
ret.push_back(proj_context_get_user_writable_directory(ctx, false));
}

const std::string envPROJ_DATA =
NS_PROJ::FileManager::getProjDataEnvVar(ctx);
const std::string relativeSharedProj = pj_get_relative_share_proj(ctx);
std::string envPROJ_DATA = NS_PROJ::FileManager::getProjDataEnvVar(ctx);
std::string relativeSharedProj = pj_get_relative_share_proj(ctx);

if (gbPROJ_DATA_ENV_VAR_TRIED_LAST) {
/* Situation where PROJ_DATA environment variable is tried in last */
#ifdef PROJ_DATA
ret.push_back(PROJ_DATA);
#endif
if (!relativeSharedProj.empty()) {
ret.push_back(relativeSharedProj);
ret.push_back(std::move(relativeSharedProj));
}
if (!envPROJ_DATA.empty()) {
ret.push_back(envPROJ_DATA);
ret.push_back(std::move(envPROJ_DATA));
}
} else {
/* Situation where PROJ_DATA environment variable is used if defined */
if (!envPROJ_DATA.empty()) {
ret.push_back(envPROJ_DATA);
ret.push_back(std::move(envPROJ_DATA));
} else {
if (!relativeSharedProj.empty()) {
ret.push_back(relativeSharedProj);
ret.push_back(std::move(relativeSharedProj));
}
#ifdef PROJ_DATA
ret.push_back(PROJ_DATA);
Expand Down Expand Up @@ -1802,7 +1801,7 @@ NS_PROJ::FileManager::open_resource_file(PJ_CONTEXT *ctx, const char *name,
auto dbContext = getDBcontext(ctx);
if (dbContext) {
try {
const auto filename = dbContext->getProjGridName(name);
auto filename = dbContext->getProjGridName(name);
if (!filename.empty()) {
file.reset(reinterpret_cast<NS_PROJ::File *>(
pj_open_lib_internal(ctx, filename.c_str(), "rb",
Expand All @@ -1814,7 +1813,7 @@ NS_PROJ::FileManager::open_resource_file(PJ_CONTEXT *ctx, const char *name,
} else {
// For final network access attempt, use the new
// name.
tmpString = filename;
tmpString = std::move(filename);
name = tmpString.c_str();
}
}
Expand Down Expand Up @@ -2020,10 +2019,9 @@ void pj_load_ini(PJ_CONTEXT *ctx) {
const auto equal = content.find('=', pos);
if (equal < eol) {
const auto key = trim(content.substr(pos, equal - pos));
const auto value =
trim(content.substr(equal + 1, eol - (equal + 1)));
auto value = trim(content.substr(equal + 1, eol - (equal + 1)));
if (ctx->endpoint.empty() && key == "cdn_endpoint") {
ctx->endpoint = value;
ctx->endpoint = std::move(value);
} else if (proj_network == nullptr && key == "network") {
ctx->networking.enabled = ci_equal(value, "ON") ||
ci_equal(value, "YES") ||
Expand Down
4 changes: 2 additions & 2 deletions src/iso19111/c_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2980,11 +2980,11 @@ proj_get_crs_info_list_from_database(PJ_CONTEXT *ctx, const char *auth_name,
int i = 0;
try {
auto dbContext = getDBcontext(ctx);
const std::string authName = auth_name ? auth_name : "";
std::string authName = auth_name ? auth_name : "";
auto actualAuthNames =
dbContext->getVersionedAuthoritiesFromName(authName);
if (actualAuthNames.empty())
actualAuthNames.push_back(authName);
actualAuthNames.push_back(std::move(authName));
std::list<AuthorityFactory::CRSInfo> concatList;
for (const auto &actualAuthName : actualAuthNames) {
auto factory = AuthorityFactory::create(dbContext, actualAuthName);
Expand Down
7 changes: 4 additions & 3 deletions src/iso19111/coordinatesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,8 @@ void CoordinateSystemAxis::_exportToWKT(io::WKTFormatter *formatter, int order,
formatter->startNode(io::WKTConstants::AXIS, !identifiers().empty());
const std::string &axisName = nameStr();
const std::string &abbrev = abbreviation();
const std::string parenthesizedAbbrev = "(" + abbrev + ")";
std::string parenthesizedAbbrev =
std::string("(").append(abbrev).append(")");
std::string dir = direction().toString();
std::string axisDesignation;

Expand Down Expand Up @@ -436,14 +437,14 @@ void CoordinateSystemAxis::_exportToWKT(io::WKTFormatter *formatter, int order,
if (direction() == AxisDirection::GEOCENTRIC_X ||
direction() == AxisDirection::GEOCENTRIC_Y ||
direction() == AxisDirection::GEOCENTRIC_Z) {
axisDesignation = parenthesizedAbbrev;
axisDesignation = std::move(parenthesizedAbbrev);
}
// For cartesian CS with Easting/Northing, export only the abbreviation
else if ((order == 1 && axisName == AxisName::Easting &&
abbrev == AxisAbbreviation::E) ||
(order == 2 && axisName == AxisName::Northing &&
abbrev == AxisAbbreviation::N)) {
axisDesignation = parenthesizedAbbrev;
axisDesignation = std::move(parenthesizedAbbrev);
}
}
formatter->addQuotedString(axisDesignation);
Expand Down
1 change: 1 addition & 0 deletions src/iso19111/datum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,7 @@ double Ellipsoid::computedInverseFlattening() PROJ_PURE_DEFN {
*/
double Ellipsoid::squaredEccentricity() PROJ_PURE_DEFN {
const double rf = computedInverseFlattening();
// coverity[divide_by_zero]
const double f = rf != 0.0 ? 1. / rf : 0.0;
const double e2 = f * (2 - f);
return e2;
Expand Down
48 changes: 24 additions & 24 deletions src/iso19111/factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3609,7 +3609,7 @@ DatabaseContext::getAliasFromOfficialName(const std::string &officialName,
std::list<std::string> l;
l.emplace_back(res2.front()[0]);
l.emplace_back((*(std::next(res2.begin())))[0]);
const auto uniqueEsriAlias = getUniqueEsriAlias(l);
std::string uniqueEsriAlias = getUniqueEsriAlias(l);
if (!uniqueEsriAlias.empty())
return uniqueEsriAlias;
}
Expand Down Expand Up @@ -5691,14 +5691,14 @@ AuthorityFactory::Private::createProjectedCRSEnd(const std::string &code,
pj_add_type_crs_if_needed(text_definition), context());
auto projCRS = dynamic_cast<const crs::ProjectedCRS *>(obj.get());
if (projCRS) {
const auto conv = projCRS->derivingConversion();
auto conv = projCRS->derivingConversion();
auto newConv =
(conv->nameStr() == "unnamed")
? operation::Conversion::create(
util::PropertyMap().set(
common::IdentifiedObject::NAME_KEY, name),
conv->method(), conv->parameterValues())
: conv;
: std::move(conv);
auto crsRet = crs::ProjectedCRS::create(
props, projCRS->baseCRS(), newConv,
projCRS->coordinateSystem());
Expand Down Expand Up @@ -6632,12 +6632,12 @@ operation::CoordinateOperationNNPtr AuthorityFactory::createCoordinateOperation(
std::string());
if (step_direction == "forward") {
++countExplicitDirection;
operations.push_back(stepOp);
operations.push_back(std::move(stepOp));
} else if (step_direction == "reverse") {
++countExplicitDirection;
operations.push_back(stepOp->inverse());
} else {
operations.push_back(stepOp);
operations.push_back(std::move(stepOp));
}
}

Expand Down Expand Up @@ -7364,7 +7364,7 @@ AuthorityFactory::createFromCRSCodesWithIntermediates(
"FROM coordinate_operation_view v1 "
"JOIN coordinate_operation_view v2 ");

const std::string joinSupersession(
const char *joinSupersession =
"LEFT JOIN supersession ss1 ON "
"ss1.superseded_table_name = v1.table_name AND "
"ss1.superseded_auth_name = v1.auth_name AND "
Expand All @@ -7376,23 +7376,23 @@ AuthorityFactory::createFromCRSCodesWithIntermediates(
"ss2.superseded_auth_name = v2.auth_name AND "
"ss2.superseded_code = v2.code AND "
"ss2.superseded_table_name = ss2.replacement_table_name AND "
"ss2.same_source_target_crs = 1 ");
"ss2.same_source_target_crs = 1 ";
const std::string joinArea(
(discardSuperseded ? joinSupersession : std::string()) +
"JOIN usage u1 ON "
"u1.object_table_name = v1.table_name AND "
"u1.object_auth_name = v1.auth_name AND "
"u1.object_code = v1.code "
"JOIN extent a1 "
"ON a1.auth_name = u1.extent_auth_name AND "
"a1.code = u1.extent_code "
"JOIN usage u2 ON "
"u2.object_table_name = v2.table_name AND "
"u2.object_auth_name = v2.auth_name AND "
"u2.object_code = v2.code "
"JOIN extent a2 "
"ON a2.auth_name = u2.extent_auth_name AND "
"a2.code = u2.extent_code ");
(discardSuperseded ? std::string(joinSupersession) : std::string())
.append("JOIN usage u1 ON "
"u1.object_table_name = v1.table_name AND "
"u1.object_auth_name = v1.auth_name AND "
"u1.object_code = v1.code "
"JOIN extent a1 "
"ON a1.auth_name = u1.extent_auth_name AND "
"a1.code = u1.extent_code "
"JOIN usage u2 ON "
"u2.object_table_name = v2.table_name AND "
"u2.object_auth_name = v2.auth_name AND "
"u2.object_code = v2.code "
"JOIN extent a2 "
"ON a2.auth_name = u2.extent_auth_name AND "
"a2.code = u2.extent_code "));
const std::string orderBy(
"ORDER BY (CASE WHEN accuracy1 is NULL THEN 1 ELSE 0 END) + "
"(CASE WHEN accuracy2 is NULL THEN 1 ELSE 0 END), "
Expand Down Expand Up @@ -9247,12 +9247,12 @@ AuthorityFactory::createObjectsFromNameEx(

const auto &auth_name = row[1];
const auto &code = row[2];
const auto key =
auto key =
std::pair<std::string, std::string>(auth_name, code);
if (setIdentified.find(key) != setIdentified.end()) {
continue;
}
setIdentified.insert(key);
setIdentified.insert(std::move(key));
auto factory = d->createFactory(auth_name);
res.emplace_back(PairObjectName(
factory->createGeodeticDatum(code), name));
Expand Down
20 changes: 10 additions & 10 deletions src/iso19111/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7367,7 +7367,7 @@ static CRSNNPtr importFromWMSAUTO(const std::string &text) {
throw ParsingException("invalid WMS AUTO CRS definition");
}

const auto getConversion = [=]() {
const auto getConversion = [dfRefLong, dfRefLat, &parts]() {
const int nProjId = std::stoi(parts[0]);
switch (nProjId) {
case 42001: // Auto UTM
Expand Down Expand Up @@ -7410,7 +7410,7 @@ static CRSNNPtr importFromWMSAUTO(const std::string &text) {
}
};

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

const Step::KeyValue pair(
Step::KeyValue pair(
(pos != std::string::npos)
? Step::KeyValue(key, word.substr(pos + 1))
: Step::KeyValue(key));
if (steps.empty()) {
globalParamValues.push_back(pair);
globalParamValues.push_back(std::move(pair));
} else {
steps.back().paramValues.push_back(pair);
steps.back().paramValues.push_back(std::move(pair));
}
}
}
Expand Down Expand Up @@ -11227,7 +11227,7 @@ PROJStringParser::Private::processAxisSwap(Step &step,
? Meridian::create(Angle(0, UnitOfMeasure::DEGREE)).as_nullable()
: nullMeridian);

const CoordinateSystemAxisNNPtr west =
CoordinateSystemAxisNNPtr west =
createAxis(isSpherical ? "Planetocentric longitude"
: isGeographic ? AxisName::Longitude
: AxisName::Westing,
Expand All @@ -11236,7 +11236,7 @@ PROJStringParser::Private::processAxisSwap(Step &step,
: std::string(),
AxisDirection::WEST, unit);

const CoordinateSystemAxisNNPtr south =
CoordinateSystemAxisNNPtr south =
createAxis(isSpherical ? "Planetocentric latitude"
: isGeographic ? AxisName::Latitude
: AxisName::Southing,
Expand Down Expand Up @@ -11292,8 +11292,8 @@ PROJStringParser::Private::processAxisSwap(Step &step,
}
} else if ((step.name == "krovak" || step.name == "mod_krovak") &&
hasParamValue(step, "czech")) {
axis[0] = west;
axis[1] = south;
axis[0] = std::move(west);
axis[1] = std::move(south);
}
return axis;
}
Expand Down
Loading
Loading