From b672c5238c3be2980eabd1e20353996b4fe24392 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Sun, 12 Jan 2025 20:11:15 +0100 Subject: [PATCH] Coverity Scan fixes --- src/apps/projinfo.cpp | 8 ++-- src/apps/projsync.cpp | 12 ++--- src/ell_set.cpp | 11 ++++- src/filemanager.cpp | 22 ++++----- src/iso19111/c_api.cpp | 4 +- src/iso19111/coordinatesystem.cpp | 7 +-- src/iso19111/datum.cpp | 1 + src/iso19111/factory.cpp | 48 +++++++++---------- src/iso19111/io.cpp | 20 ++++---- src/iso19111/operation/conversion.cpp | 8 ++-- .../operation/coordinateoperationfactory.cpp | 48 ++++++++++--------- src/iso19111/operation/oputils.cpp | 2 +- src/iso19111/operation/projbasedoperation.cpp | 2 +- src/iso19111/operation/singleoperation.cpp | 2 +- src/iso19111/operation/transformation.cpp | 5 +- src/projections/airocean.cpp | 8 ++++ src/transformations/defmodel_impl.hpp | 14 +++--- 17 files changed, 122 insertions(+), 100 deletions(-) diff --git a/src/apps/projinfo.cpp b/src/apps/projinfo.cpp index debaea6352..f32f9964a1 100644 --- a/src/apps/projinfo.cpp +++ b/src/apps/projinfo.cpp @@ -488,7 +488,7 @@ static void outputObject( std::cout << std::endl; } - const auto projStringExportable = + auto projStringExportable = nn_dynamic_pointer_cast(obj); bool alreadyOutputted = false; if (projStringExportable) { @@ -511,7 +511,7 @@ static void outputObject( dbContext, allowUseIntermediateCRS)); } if (!objToExport) { - objToExport = projStringExportable; + objToExport = std::move(projStringExportable); } auto formatter = PROJStringFormatter::create( @@ -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++; @@ -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)); } } diff --git a/src/apps/projsync.cpp b/src/apps/projsync.cpp index e4399a4fd5..dcaf3e6433 100644 --- a/src/apps/projsync.cpp +++ b/src/apps/projsync.cpp @@ -90,10 +90,10 @@ static std::vector 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]); @@ -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)); } } } @@ -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." diff --git a/src/ell_set.cpp b/src/ell_set.cpp index 89c605184b..48e3bfebf9 100644 --- a/src/ell_set.cpp +++ b/src/ell_set.cpp @@ -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); @@ -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; @@ -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; diff --git a/src/filemanager.cpp b/src/filemanager.cpp index 90d16d6134..b2e91b0c21 100644 --- a/src/filemanager.cpp +++ b/src/filemanager.cpp @@ -1721,9 +1721,8 @@ std::vector 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 */ @@ -1731,18 +1730,18 @@ std::vector pj_get_default_searchpaths(PJ_CONTEXT *ctx) { 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); @@ -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( 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, } else { // For final network access attempt, use the new // name. - tmpString = filename; + tmpString = std::move(filename); name = tmpString.c_str(); } } @@ -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") || diff --git a/src/iso19111/c_api.cpp b/src/iso19111/c_api.cpp index dbf1cfb738..acefc44201 100644 --- a/src/iso19111/c_api.cpp +++ b/src/iso19111/c_api.cpp @@ -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 concatList; for (const auto &actualAuthName : actualAuthNames) { auto factory = AuthorityFactory::create(dbContext, actualAuthName); diff --git a/src/iso19111/coordinatesystem.cpp b/src/iso19111/coordinatesystem.cpp index 459a1c155d..2ed2f81d58 100644 --- a/src/iso19111/coordinatesystem.cpp +++ b/src/iso19111/coordinatesystem.cpp @@ -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; @@ -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); diff --git a/src/iso19111/datum.cpp b/src/iso19111/datum.cpp index 02d3356fdb..14467e1b2c 100644 --- a/src/iso19111/datum.cpp +++ b/src/iso19111/datum.cpp @@ -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; diff --git a/src/iso19111/factory.cpp b/src/iso19111/factory.cpp index 793bffae58..ff5a632c9e 100644 --- a/src/iso19111/factory.cpp +++ b/src/iso19111/factory.cpp @@ -3609,7 +3609,7 @@ DatabaseContext::getAliasFromOfficialName(const std::string &officialName, std::list 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; } @@ -5691,14 +5691,14 @@ AuthorityFactory::Private::createProjectedCRSEnd(const std::string &code, pj_add_type_crs_if_needed(text_definition), context()); auto projCRS = dynamic_cast(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()); @@ -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)); } } @@ -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 " @@ -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), " @@ -9247,12 +9247,12 @@ AuthorityFactory::createObjectsFromNameEx( const auto &auth_name = row[1]; const auto &code = row[2]; - const auto key = + auto key = std::pair(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)); diff --git a/src/iso19111/io.cpp b/src/iso19111/io.cpp index 1bf35eae9e..5624ae0946 100644 --- a/src/iso19111/io.cpp +++ b/src/iso19111/io.cpp @@ -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 @@ -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; @@ -9965,16 +9965,16 @@ PROJStringSyntaxParser(const std::string &projString, std::vector &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)); } } } @@ -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, @@ -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, @@ -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; } diff --git a/src/iso19111/operation/conversion.cpp b/src/iso19111/operation/conversion.cpp index ffeb761005..c5d9ddfb3e 100644 --- a/src/iso19111/operation/conversion.cpp +++ b/src/iso19111/operation/conversion.cpp @@ -276,8 +276,7 @@ createConversion(const util::PropertyMap &properties, metadata::Identifier::EPSG) .set(metadata::Identifier::CODE_KEY, param->epsg_code); } - auto parameter = OperationParameter::create(paramProperties); - parameters.push_back(parameter); + parameters.push_back(OperationParameter::create(paramProperties)); } auto methodProperties = util::PropertyMap().set( @@ -2713,9 +2712,11 @@ CoordinateOperationNNPtr Conversion::inverse() const { if (convFactor == 0) { throw InvalidOperation("Invalid conversion factor"); } + // coverity[divide_by_zero] + const double invConvFactor = 1.0 / convFactor; auto conv = createChangeVerticalUnit( createPropertiesForInverse(this, false, false), - common::Scale(1.0 / convFactor)); + common::Scale(invConvFactor)); conv->setCRSs(this, true); return conv; } @@ -2880,6 +2881,7 @@ ConversionPtr Conversion::convertToOtherMethod(int targetEPSGCode) const { EPSG_CODE_PARAMETER_SCALE_FACTOR_AT_NATURAL_ORIGIN); if (!(k0 > 0 && k0 <= 1.0 + 1e-10)) return nullptr; + // coverity[divide_by_zero] const double dfStdP1Lat = (k0 >= 1.0) ? 0.0 diff --git a/src/iso19111/operation/coordinateoperationfactory.cpp b/src/iso19111/operation/coordinateoperationfactory.cpp index b36dcd5e04..336127f680 100644 --- a/src/iso19111/operation/coordinateoperationfactory.cpp +++ b/src/iso19111/operation/coordinateoperationfactory.cpp @@ -852,9 +852,6 @@ struct PrecomputedOpCharacteristics { // filterAndSort() is already huge. struct SortFunction { - const std::map ↦ - const std::string BALLPARK_GEOGRAPHIC_OFFSET_FROM; - explicit SortFunction(const std::map &mapIn) : map(mapIn), BALLPARK_GEOGRAPHIC_OFFSET_FROM( @@ -1083,6 +1080,15 @@ struct SortFunction { #endif return ret; } + + SortFunction(const SortFunction &) = default; + SortFunction &operator=(const SortFunction &) = delete; + SortFunction(SortFunction &&) = default; + SortFunction &operator=(SortFunction &&) = delete; + + private: + const std::map ↦ + const std::string BALLPARK_GEOGRAPHIC_OFFSET_FROM; }; // --------------------------------------------------------------------------- @@ -1467,8 +1473,7 @@ struct FilterResults { } // Sort ! - SortFunction sortFunc(map); - std::sort(res.begin(), res.end(), sortFunc); + std::sort(res.begin(), res.end(), SortFunction(map)); // Debug code to check consistency of the sort function #ifdef DEBUG_SORT @@ -1478,6 +1483,7 @@ struct FilterResults { #endif #if defined(DEBUG_SORT) || !defined(NDEBUG) if (debugSort) { + SortFunction sortFunc(map); const bool assertIfIssue = !(getenv("PROJ_DEBUG_SORT_FUNCT_ASSERT") != nullptr); for (size_t i = 0; i < res.size(); ++i) { @@ -1538,7 +1544,7 @@ struct FilterResults { for (const auto &op : res) { const auto curAccuracy = getAccuracy(op); bool dummy = false; - const auto curExtent = getExtent(op, true, dummy); + auto curExtent = getExtent(op, true, dummy); // If a concatenated operation has an identifier, consider it as // a single step (to be opposed to synthesized concatenated // operations). Helps for example to get EPSG:8537, @@ -1569,7 +1575,7 @@ struct FilterResults { lastOp = op.as_nullable(); lastStepCount = curStepCount; - lastExtent = curExtent; + lastExtent = std::move(curExtent); lastAccuracy = curAccuracy; } res = std::move(resTemp); @@ -1624,7 +1630,7 @@ struct FilterResults { if (setPROJPlusExtent.find(key) == setPROJPlusExtent.end()) { resTemp.emplace_back(op); - setPROJPlusExtent.insert(key); + setPROJPlusExtent.insert(std::move(key)); } } catch (const std::exception &) { resTemp.emplace_back(op); @@ -5869,27 +5875,25 @@ void CoordinateOperationFactory::Private::createOperationsCompoundToGeog( "CGVD2013a(1997) height") || (is2002 && componentsSrc[1]->nameStr() == "CGVD2013a(2002) height"))) { - const auto newGeogCRS_2D( + std::vector intermComponents{ authFactoryEPSG->createCoordinateReferenceSystem( is1997 ? "8240" : // NAD83(CSRS)v3 2D "8246" // NAD83(CSRS)v4 2D - )); - const auto newGeogCRS_3D( - authFactoryEPSG->createCoordinateReferenceSystem( - is1997 ? "8239" : // NAD83(CSRS)v3 3D - "8244" // NAD83(CSRS)v4 3D - )); - std::vector intermComponents{ - newGeogCRS_2D, componentsSrc[1]}; + ), + componentsSrc[1]}; auto properties = util::PropertyMap().set( common::IdentifiedObject::NAME_KEY, intermComponents[0]->nameStr() + " + " + intermComponents[1]->nameStr()); auto newCompound = crs::CompoundCRS::create( properties, intermComponents); - auto ops = createOperations(newCompound, sourceEpoch, - newGeogCRS_3D, sourceEpoch, - context); + auto ops = createOperations( + newCompound, sourceEpoch, + authFactoryEPSG->createCoordinateReferenceSystem( + is1997 ? "8239" : // NAD83(CSRS)v3 3D + "8244" // NAD83(CSRS)v4 3D + ), + sourceEpoch, context); for (const auto &op : ops) { auto opClone = op->shallowClone(); setCRSs(opClone.get(), sourceCRS, targetCRS); @@ -6156,7 +6160,7 @@ void CoordinateOperationFactory::Private::createOperationsCompoundToGeog( } if (horizTransforms.empty() || verticalTransforms.empty()) { - res = horizTransforms; + res = std::move(horizTransforms); return; } @@ -7371,7 +7375,7 @@ crs::CRSNNPtr CRS::getResolvedCRS(const crs::CRSNNPtr &crs, auto matches = authFactory->createObjectsFromName( name, {objectType}, false, 2); if (matches.size() == 1) { - const auto match = + auto match = util::nn_static_pointer_cast(matches.front()); if (approxExtent || !extentOut) { extentOut = operation::getExtent(match); diff --git a/src/iso19111/operation/oputils.cpp b/src/iso19111/operation/oputils.cpp index 6910937b05..60bdb09eba 100644 --- a/src/iso19111/operation/oputils.cpp +++ b/src/iso19111/operation/oputils.cpp @@ -287,7 +287,7 @@ util::PropertyMap createPropertiesForInverse(const CoordinateOperation *op, } } if (!curToken.empty()) { - tokens.push_back(curToken); + tokens.push_back(std::move(curToken)); } for (size_t i = tokens.size(); i > 0;) { i--; diff --git a/src/iso19111/operation/projbasedoperation.cpp b/src/iso19111/operation/projbasedoperation.cpp index f7ac4ea091..84d8ecad56 100644 --- a/src/iso19111/operation/projbasedoperation.cpp +++ b/src/iso19111/operation/projbasedoperation.cpp @@ -314,7 +314,7 @@ PROJBasedOperation::gridsNeeded(const io::DatabaseContextPtr &databaseContext, desc.fullName, desc.packageName, desc.url, desc.directDownload, desc.openLicense, desc.available); } - res.insert(desc); + res.insert(std::move(desc)); } } catch (const io::ParsingException &) { } diff --git a/src/iso19111/operation/singleoperation.cpp b/src/iso19111/operation/singleoperation.cpp index fc13b4bd28..7353877c51 100644 --- a/src/iso19111/operation/singleoperation.cpp +++ b/src/iso19111/operation/singleoperation.cpp @@ -1725,7 +1725,7 @@ SingleOperation::gridsNeeded(const io::DatabaseContextPtr &databaseContext, desc.directDownload, desc.openLicense, desc.available); } - res.insert(desc); + res.insert(std::move(desc)); } } } diff --git a/src/iso19111/operation/transformation.cpp b/src/iso19111/operation/transformation.cpp index 4ed5198a84..fba00f09aa 100644 --- a/src/iso19111/operation/transformation.cpp +++ b/src/iso19111/operation/transformation.cpp @@ -1733,11 +1733,12 @@ TransformationNNPtr Transformation::inverseAsTransformation() const { if (methodEPSGCode == EPSG_CODE_METHOD_CHANGE_VERTICAL_UNIT) { const double convFactor = parameterValueNumericAsSI( EPSG_CODE_PARAMETER_UNIT_CONVERSION_SCALAR); + // coverity[divide_by_zero] + const double invConvFactor = convFactor == 0.0 ? 0.0 : 1.0 / convFactor; return Private::registerInv( this, createChangeVerticalUnit( createPropertiesForInverse(this, false, false), - l_targetCRS, l_sourceCRS, - common::Scale(convFactor == 0.0 ? 0.0 : 1.0 / convFactor), + l_targetCRS, l_sourceCRS, common::Scale(invConvFactor), coordinateOperationAccuracies())); } diff --git a/src/projections/airocean.cpp b/src/projections/airocean.cpp index 2630e1e146..29e7277d19 100644 --- a/src/projections/airocean.cpp +++ b/src/projections/airocean.cpp @@ -756,6 +756,14 @@ static PJ_XY airocean_forward(PJ_LP lp, PJ *P) { PJ_XYZ cartesianPoint{x, y, z}; unsigned char face_id = get_ico_face_index(Q, &cartesianPoint); + if (face_id == 23) { + // not sure this can happen + proj_errno_set(P, PROJ_ERR_COORD_TRANSFM_OUTSIDE_PROJECTION_DOMAIN); + PJ_XY xy; + xy.x = HUGE_VAL; + xy.y = HUGE_VAL; + return xy; + } PJ_XYZ icoPoint = cartesian_to_ico(Q, &cartesianPoint, face_id); diff --git a/src/transformations/defmodel_impl.hpp b/src/transformations/defmodel_impl.hpp index 1e9fbab659..41384414b8 100644 --- a/src/transformations/defmodel_impl.hpp +++ b/src/transformations/defmodel_impl.hpp @@ -539,35 +539,35 @@ Component Component::parse(const json &j) { getOptString(jSpatialModel, "md5_checksum"); const json jTimeFunction = getObjectMember(j, "time_function"); - const std::string timeFunctionType = getReqString(jTimeFunction, "type"); + std::string timeFunctionType = getReqString(jTimeFunction, "type"); const json jParameters = timeFunctionType == "constant" ? json() : getObjectMember(jTimeFunction, "parameters"); if (timeFunctionType == "constant") { std::unique_ptr tf(new ConstantTimeFunction()); - tf->type = timeFunctionType; + tf->type = std::move(timeFunctionType); comp.mTimeFunction = std::move(tf); } else if (timeFunctionType == "velocity") { std::unique_ptr tf(new VelocityTimeFunction()); - tf->type = timeFunctionType; + tf->type = std::move(timeFunctionType); tf->referenceEpoch = Epoch(getReqString(jParameters, "reference_epoch")); comp.mTimeFunction = std::move(tf); } else if (timeFunctionType == "step") { std::unique_ptr tf(new StepTimeFunction()); - tf->type = timeFunctionType; + tf->type = std::move(timeFunctionType); tf->stepEpoch = Epoch(getReqString(jParameters, "step_epoch")); comp.mTimeFunction = std::move(tf); } else if (timeFunctionType == "reverse_step") { std::unique_ptr tf( new ReverseStepTimeFunction()); - tf->type = timeFunctionType; + tf->type = std::move(timeFunctionType); tf->stepEpoch = Epoch(getReqString(jParameters, "step_epoch")); comp.mTimeFunction = std::move(tf); } else if (timeFunctionType == "piecewise") { std::unique_ptr tf(new PiecewiseTimeFunction()); - tf->type = timeFunctionType; + tf->type = std::move(timeFunctionType); tf->beforeFirst = getReqString(jParameters, "before_first"); if (tf->beforeFirst != "zero" && tf->beforeFirst != "constant" && tf->beforeFirst != "linear") { @@ -593,7 +593,7 @@ Component Component::parse(const json &j) { } else if (timeFunctionType == "exponential") { std::unique_ptr tf( new ExponentialTimeFunction()); - tf->type = timeFunctionType; + tf->type = std::move(timeFunctionType); tf->referenceEpoch = Epoch(getReqString(jParameters, "reference_epoch")); tf->endEpoch = Epoch(getOptString(jParameters, "end_epoch"));