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

Fix most Coverity Scan performance warnings #3989

Merged
merged 1 commit into from
Jan 8, 2024
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
3 changes: 2 additions & 1 deletion src/apps/proj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,7 @@ int main(int argc, char **argv) {
eargv++;
eargc--;
// logic copied from proj_factors function
// coverity[tainted_data]
if (PJ *P = proj_create(nullptr, ocrs.c_str())) {
auto type = proj_get_type(P);
auto ctx = P->ctx;
Expand All @@ -555,7 +556,7 @@ int main(int argc, char **argv) {
try {
auto crs = dynamic_cast<const NS_PROJ::crs::ProjectedCRS *>(
P->iso_obj.get());
auto& dir =
auto &dir =
crs->coordinateSystem()->axisList()[0]->direction();
swapAxisCrs = dir == NS_PROJ::cs::AxisDirection::NORTH ||
dir == NS_PROJ::cs::AxisDirection::SOUTH;
Expand Down
18 changes: 9 additions & 9 deletions src/apps/projinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ static void outputObject(
std::cout << std::endl;
}

auto projStringExportable =
const auto projStringExportable =
nn_dynamic_pointer_cast<IPROJStringExportable>(obj);
bool alreadyOutputted = false;
if (projStringExportable) {
Expand Down Expand Up @@ -769,7 +769,7 @@ static void outputOperationSummary(

std::cout << ", ";

auto name = op->nameStr();
const auto &name = op->nameStr();
if (!name.empty()) {
std::cout << name;
} else {
Expand All @@ -778,7 +778,7 @@ static void outputOperationSummary(

std::cout << ", ";

auto accuracies = op->coordinateOperationAccuracies();
const auto &accuracies = op->coordinateOperationAccuracies();
if (!accuracies.empty()) {
std::cout << accuracies[0]->value() << " m";
} else {
Expand All @@ -791,7 +791,7 @@ static void outputOperationSummary(

std::cout << ", ";

auto domains = op->domains();
const auto &domains = op->domains();
if (!domains.empty() && domains[0]->domainOfValidity() &&
domains[0]->domainOfValidity()->description().has_value()) {
std::cout << *(domains[0]->domainOfValidity()->description());
Expand All @@ -805,7 +805,7 @@ static void outputOperationSummary(

if (dbContext && getenv("PROJINFO_NO_GRID_CHECK") == nullptr) {
try {
auto setGrids = op->gridsNeeded(dbContext, false);
const auto setGrids = op->gridsNeeded(dbContext, false);
for (const auto &grid : setGrids) {
if (!grid.available) {
std::cout << ", at least one grid missing";
Expand Down Expand Up @@ -841,7 +841,7 @@ static bool is3DCRS(const CRSPtr &crs) {
// ---------------------------------------------------------------------------

static void outputOperations(
DatabaseContextPtr dbContext, const std::string &sourceCRSStr,
const DatabaseContextPtr &dbContext, const std::string &sourceCRSStr,
const std::string &sourceEpoch, const std::string &targetCRSStr,
const std::string &targetEpoch, const ExtentPtr &bboxFilter,
CoordinateOperationContext::SpatialCriterion spatialCriterion,
Expand Down Expand Up @@ -907,7 +907,7 @@ static void outputOperations(
auto promoted =
sourceCRS->promoteTo3D(std::string(), dbContext).as_nullable();
if (!promoted->identifiers().empty()) {
sourceCRS = promoted;
sourceCRS = std::move(promoted);
}
} else if (is3DCRS(sourceCRS) && !is3DCRS(targetCRS) &&
!targetCRS->identifiers().empty() &&
Expand All @@ -916,7 +916,7 @@ static void outputOperations(
auto promoted =
targetCRS->promoteTo3D(std::string(), dbContext).as_nullable();
if (!promoted->identifiers().empty()) {
targetCRS = promoted;
targetCRS = std::move(promoted);
}
}
}
Expand Down Expand Up @@ -1078,7 +1078,7 @@ int main(int argc, char **argv) {
bool listCRSSpecified = false;

for (int i = 1; i < argc; i++) {
std::string arg(argv[i]);
const std::string arg(argv[i]);
if (arg == "-o" && i + 1 < argc) {
outputSwitchSpecified = true;
i++;
Expand Down
6 changes: 3 additions & 3 deletions src/filemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1203,7 +1203,7 @@ const char *proj_context_get_user_writable_directory(PJ_CONTEXT *ctx,
}
#endif
path += "/proj";
ctx->user_writable_directory = path;
ctx->user_writable_directory = std::move(path);
}
if (create != FALSE) {
CreateDirectoryRecursively(ctx, ctx->user_writable_directory);
Expand Down Expand Up @@ -1655,7 +1655,7 @@ NS_PROJ::FileManager::open_resource_file(PJ_CONTEXT *ctx, const char *name,
auto dbContext = getDBcontext(ctx);
if (dbContext) {
try {
auto filename = dbContext->getProjGridName(name);
const 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 Down Expand Up @@ -1686,7 +1686,7 @@ NS_PROJ::FileManager::open_resource_file(PJ_CONTEXT *ctx, const char *name,
auto dbContext = getDBcontext(ctx);
if (dbContext) {
try {
auto filename = dbContext->getOldProjGridName(name);
const auto filename = dbContext->getOldProjGridName(name);
if (!filename.empty()) {
file.reset(reinterpret_cast<NS_PROJ::File *>(
pj_open_lib_internal(ctx, filename.c_str(), "rb",
Expand Down
6 changes: 3 additions & 3 deletions src/grids.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1613,7 +1613,7 @@ VerticalShiftGridSet::open(PJ_CONTEXT *ctx, const std::string &filename) {
if (!fp) {
return nullptr;
}
const auto actualName(fp->name());
const auto &actualName(fp->name());
if (ends_with(actualName, "gtx") || ends_with(actualName, "GTX")) {
auto grid = GTXVerticalShiftGrid::open(ctx, std::move(fp), actualName);
if (!grid) {
Expand Down Expand Up @@ -2657,7 +2657,7 @@ HorizontalShiftGridSet::open(PJ_CONTEXT *ctx, const std::string &filename) {
if (!fp) {
return nullptr;
}
const auto actualName(fp->name());
const auto &actualName(fp->name());

char header[160];
/* -------------------------------------------------------------------- */
Expand Down Expand Up @@ -3086,7 +3086,6 @@ GenericShiftGridSet::open(PJ_CONTEXT *ctx, const std::string &filename) {
if (!fp) {
return nullptr;
}
const auto actualName(fp->name());

/* -------------------------------------------------------------------- */
/* Load a header, to determine the file type. */
Expand All @@ -3100,6 +3099,7 @@ GenericShiftGridSet::open(PJ_CONTEXT *ctx, const std::string &filename) {

if (IsTIFF(header_size, header)) {
#ifdef TIFF_ENABLED
const std::string actualName(fp->name());
auto set = std::unique_ptr<GenericShiftGridSet>(
GTiffGenericGridShiftSet::open(ctx, std::move(fp), actualName));
if (!set)
Expand Down
24 changes: 13 additions & 11 deletions src/iso19111/c_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ PJ *pj_obj_create(PJ_CONTEXT *ctx, const BaseObjectNNPtr &objIn) {
auto dbContext = getDBcontextNoException(ctx, __FUNCTION__);
try {
auto formatter = PROJStringFormatter::create(
PROJStringFormatter::Convention::PROJ_5, dbContext);
PROJStringFormatter::Convention::PROJ_5, std::move(dbContext));
auto projString = coordop->exportToPROJString(formatter.get());
if (proj_context_is_network_enabled(ctx)) {
ctx->defer_grid_opening = true;
Expand Down Expand Up @@ -380,7 +380,7 @@ const char *proj_context_get_database_path(PJ_CONTEXT *ctx) {
try {
// temporary variable must be used as getDBcontext() might create
// ctx->cpp_context
auto osPath(getDBcontext(ctx)->getPath());
const auto osPath(getDBcontext(ctx)->getPath());
ctx->get_cpp_context()->lastDbPath_ = osPath;
return ctx->cpp_context->lastDbPath_.c_str();
} catch (const std::exception &e) {
Expand Down Expand Up @@ -1629,7 +1629,7 @@ const char *proj_as_wkt(PJ_CONTEXT *ctx, const PJ *obj, PJ_WKT_TYPE type,

try {
auto dbContext = getDBcontextNoException(ctx, __FUNCTION__);
auto formatter = WKTFormatter::create(convention, dbContext);
auto formatter = WKTFormatter::create(convention, std::move(dbContext));
for (auto iter = options; iter && iter[0]; ++iter) {
const char *value;
if ((value = getOptionValue(*iter, "MULTILINE="))) {
Expand Down Expand Up @@ -1735,7 +1735,8 @@ const char *proj_as_proj_string(PJ_CONTEXT *ctx, const PJ *obj,
static_cast<PROJStringFormatter::Convention>(type);
auto dbContext = getDBcontextNoException(ctx, __FUNCTION__);
try {
auto formatter = PROJStringFormatter::create(convention, dbContext);
auto formatter =
PROJStringFormatter::create(convention, std::move(dbContext));
for (auto iter = options; iter && iter[0]; ++iter) {
const char *value;
if ((value = getOptionValue(*iter, "MULTILINE="))) {
Expand Down Expand Up @@ -1807,7 +1808,7 @@ const char *proj_as_projjson(PJ_CONTEXT *ctx, const PJ *obj,

auto dbContext = getDBcontextNoException(ctx, __FUNCTION__);
try {
auto formatter = JSONFormatter::create(dbContext);
auto formatter = JSONFormatter::create(std::move(dbContext));
for (auto iter = options; iter && iter[0]; ++iter) {
const char *value;
if ((value = getOptionValue(*iter, "MULTILINE="))) {
Expand Down Expand Up @@ -4681,12 +4682,13 @@ static CoordinateSystemAxisNNPtr createAxis(const PJ_AXIS_DESCRIPTION &axis) {
unit_type = UnitOfMeasure::Type::PARAMETRIC;
break;
}
auto unit = axis.unit_type == PJ_UT_ANGULAR
? createAngularUnit(axis.unit_name, axis.unit_conv_factor)
: axis.unit_type == PJ_UT_LINEAR
? createLinearUnit(axis.unit_name, axis.unit_conv_factor)
: UnitOfMeasure(axis.unit_name ? axis.unit_name : "unnamed",
axis.unit_conv_factor, unit_type);
const common::UnitOfMeasure unit(
axis.unit_type == PJ_UT_ANGULAR
? createAngularUnit(axis.unit_name, axis.unit_conv_factor)
: axis.unit_type == PJ_UT_LINEAR
? createLinearUnit(axis.unit_name, axis.unit_conv_factor)
: UnitOfMeasure(axis.unit_name ? axis.unit_name : "unnamed",
axis.unit_conv_factor, unit_type));

return CoordinateSystemAxis::create(
createPropertyMapName(axis.name),
Expand Down
2 changes: 1 addition & 1 deletion src/iso19111/coordinatesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ 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();
std::string parenthesizedAbbrev = "(" + abbrev + ")";
const std::string parenthesizedAbbrev = "(" + abbrev + ")";
std::string dir = direction().toString();
std::string axisDesignation;

Expand Down
Loading
Loading