Skip to content

Commit

Permalink
Avoid/fix Coverity performance warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed Jan 16, 2024
1 parent c1783d9 commit 307106b
Show file tree
Hide file tree
Showing 153 changed files with 549 additions and 536 deletions.
4 changes: 2 additions & 2 deletions apps/gdal_translate_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1083,7 +1083,7 @@ GDALDatasetH GDALTranslate(const char *pszDest, GDALDatasetH hSrcDataset,
/* -------------------------------------------------------------------- */
if (psOptions->osFormat.empty())
{
CPLString osFormat = GetOutputDriverForRaster(pszDest);
const std::string osFormat = GetOutputDriverForRaster(pszDest);
if (osFormat.empty())
{
GDALTranslateOptionsFree(psOptions);
Expand Down Expand Up @@ -1641,7 +1641,7 @@ GDALDatasetH GDALTranslate(const char *pszDest, GDALDatasetH hSrcDataset,
fabs(adfSrcGeoTransform[5] / adfDstGeoTransform[5]);
}

const auto adfSrcWinOri = psOptions->adfSrcWin;
const std::array<double, 4> adfSrcWinOri(psOptions->adfSrcWin);
const double dfRatioX =
poSrcDS->GetRasterXSize() == 0
? 1.0
Expand Down
4 changes: 2 additions & 2 deletions apps/gdalmdiminfo_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ static void DumpArrayRec(std::shared_ptr<GDALMDArray> array,
auto arrayContext(serializer.MakeArrayContext());
if (nCurDim + 1 == dimSizes.size())
{
const auto dt(array->GetDataType());
const auto &dt(array->GetDataType());
const auto nDTSize(dt.GetSize());
const auto lambdaDumpValue =
[&serializer, &dt, nDTSize](std::vector<GByte> &abyTmp,
Expand Down Expand Up @@ -805,7 +805,7 @@ static void DumpArray(const std::shared_ptr<GDALGroup> &rootGroup,
DumpAttrs(attrs, serializer, psOptions);
}

auto unit = array->GetUnit();
const auto &unit = array->GetUnit();
if (!unit.empty())
{
serializer.AddObjKey("unit");
Expand Down
8 changes: 4 additions & 4 deletions apps/gdalmdimtranslate_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,7 @@ static bool TranslateArray(
auto tmpArrayNew = tmpArray->GetView(viewExpr, false, viewSpecs);
if (!tmpArrayNew)
return false;
tmpArray = tmpArrayNew;
tmpArray = std::move(tmpArrayNew);
size_t j = 0;
const auto &tmpArrayDims(tmpArray->GetDimensions());
for (size_t i = 0; i < srcArrayDims.size(); ++i)
Expand Down Expand Up @@ -1086,7 +1086,7 @@ static bool TranslateArray(
CPLErrorStateBackuper oErrorStateBackuper;
auto poDstIndexingVar(poDstGroup->OpenMDArray(newDimName));
if (poDstIndexingVar)
dstDim->SetIndexingVariable(poDstIndexingVar);
dstDim->SetIndexingVariable(std::move(poDstIndexingVar));
}
}
if (outputType.GetClass() == GEDTC_NUMERIC &&
Expand Down Expand Up @@ -1230,7 +1230,7 @@ GetGroup(const std::shared_ptr<GDALGroup> &poRootGroup,
aosTokens[i]);
return nullptr;
}
poCurGroup = poCurGroupNew;
poCurGroup = std::move(poCurGroupNew);
}
return poCurGroup;
}
Expand Down Expand Up @@ -1560,7 +1560,7 @@ CopyToNonMultiDimensionalDriver(GDALDriver *poDriver, const char *pszDest,
"output to non-multidimensional driver");
return nullptr;
}
srcArray = tmpArray;
srcArray = std::move(tmpArray);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion apps/gdalwarp_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1402,7 +1402,7 @@ GDALDatasetH GDALWarp(const char *pszDest, GDALDatasetH hDstDS, int nSrcCount,
{
if (psOptions->osFormat.empty())
{
CPLString osFormat = GetOutputDriverForRaster(pszDest);
const std::string osFormat = GetOutputDriverForRaster(pszDest);
if (osFormat.empty())
{
return nullptr;
Expand Down
4 changes: 2 additions & 2 deletions apps/ogrinfo_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,7 @@ static void GDALVectorInfoReportMetadata(CPLString &osRet, CPLJSONObject &oRoot,
/* ReportOnLayer() */
/************************************************************************/

static void ReportOnLayer(CPLString &osRet, CPLJSONObject oLayer,
static void ReportOnLayer(CPLString &osRet, CPLJSONObject &oLayer,
const GDALVectorInfoOptions *psOptions,
OGRLayer *poLayer, bool bForceSummary,
bool bTakeIntoAccountWHERE,
Expand Down Expand Up @@ -1146,7 +1146,7 @@ static void ReportOnLayer(CPLString &osRet, CPLJSONObject oLayer,
"Coordinate epoch: %s\n", osCoordinateEpoch.c_str());
}

const auto mapping = poSRS->GetDataAxisToSRSAxisMapping();
const auto &mapping = poSRS->GetDataAxisToSRSAxisMapping();
Concat(osRet, psOptions->bStdoutOutput,
"Data axis to CRS axis mapping: ");
for (size_t i = 0; i < mapping.size(); i++)
Expand Down
2 changes: 2 additions & 0 deletions autotest/cpp/test_cpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2563,9 +2563,11 @@ TEST_F(test_cpl, CPLJSONDocument)
CPLJSONObject oObj2(oObj);
ASSERT_TRUE(oObj2.ToBool());
// Assignment operator
// coverity[copy_assignment_call]
oDocument2 = oDocument;
auto &oDocument2Ref(oDocument2);
oDocument2 = oDocument2Ref;
// coverity[copy_assignment_call]
oObj2 = oObj;
auto &oObj2Ref(oObj2);
oObj2 = oObj2Ref;
Expand Down
2 changes: 1 addition & 1 deletion autotest/cpp/test_ogr_organize_polygons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class OrganizePolygonsTest : public testing::TestWithParam<std::string>
INSTANTIATE_TEST_SUITE_P(
test_gdal, OrganizePolygonsTest,
::testing::Values("DEFAULT", "ONLY_CCW", "SKIP"),
[](const ::testing::TestParamInfo<std::string> &param_info)
[](const ::testing::TestParamInfo<std::string> &param_info) -> std::string
{ return param_info.param; });

TEST_P(OrganizePolygonsTest, EmptyInputVector)
Expand Down
5 changes: 2 additions & 3 deletions frmts/aaigrid/aaigriddataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -798,8 +798,7 @@ int ISGDataset::ParseHeader(const char *pszHeader, const char *)
{
CPLString osLeft(aosTokens[0]);
osLeft.Trim();
CPLString osRight(aosTokens[1]);
osRight.Trim();
const CPLString osRight(CPLString(aosTokens[1]).Trim());
if (osLeft == "lat min")
osLatMin = osRight;
else if (osLeft == "lat max")
Expand Down Expand Up @@ -1251,7 +1250,7 @@ GDALDataset *AAIGDataset::CommonOpen(GDALOpenInfo *poOpenInfo,
poDS->adfGeoTransform[5] /= 3600.0;
}

poDS->m_oSRS = oSRS;
poDS->m_oSRS = std::move(oSRS);
}
}

Expand Down
2 changes: 1 addition & 1 deletion frmts/adrg/adrgdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1489,7 +1489,7 @@ char **ADRGDataset::GetIMGListFromGEN(const char *pszFileName,
/* Build full IMG file name from BAD value */
CPLString osGENDir(CPLGetDirname(pszFileName));

CPLString osFileName =
const CPLString osFileName =
CPLFormFilename(osGENDir.c_str(), osBAD.c_str(), nullptr);
VSIStatBufL sStatBuf;
if (VSIStatL(osFileName, &sStatBuf) == 0)
Expand Down
4 changes: 2 additions & 2 deletions frmts/adrg/srpdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1414,9 +1414,9 @@ char **SRPDataset::GetIMGListFromGEN(const char *pszFileName,
CPLDebug("SRP", "BAD=%s", osBAD.c_str());

/* Build full IMG file name from BAD value */
CPLString osGENDir(CPLGetDirname(pszFileName));
const CPLString osGENDir(CPLGetDirname(pszFileName));

CPLString osFileName =
const CPLString osFileName =
CPLFormFilename(osGENDir.c_str(), osBAD.c_str(), nullptr);
VSIStatBufL sStatBuf;
if (VSIStatL(osFileName, &sStatBuf) == 0)
Expand Down
2 changes: 1 addition & 1 deletion frmts/aigrid/aigdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ GDALDataset *AIGDataset::Open(GDALOpenInfo *poOpenInfo)
psInfo->dfCellSizeY /= 3600.0;
}

poDS->m_oSRS = oSRS;
poDS->m_oSRS = std::move(oSRS);
}
}

Expand Down
15 changes: 9 additions & 6 deletions frmts/daas/daasdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -478,13 +478,13 @@ static CPLHTTPResult *DAAS_CPLHTTPFetch(const char *pszURL, char **papszOptions)

bool GDALDAASDataset::GetAuthorization()
{
CPLString osClientId =
const CPLString osClientId =
CSLFetchNameValueDef(m_papszOpenOptions, "CLIENT_ID",
CPLGetConfigOption("GDAL_DAAS_CLIENT_ID", ""));
CPLString osAPIKey =
const CPLString osAPIKey =
CSLFetchNameValueDef(m_papszOpenOptions, "API_KEY",
CPLGetConfigOption("GDAL_DAAS_API_KEY", ""));
CPLString osAuthorization =
const CPLString osAuthorization =
CSLFetchNameValueDef(m_papszOpenOptions, "ACCESS_TOKEN",
CPLGetConfigOption("GDAL_DAAS_ACCESS_TOKEN", ""));
m_osXForwardUser = CSLFetchNameValueDef(
Expand Down Expand Up @@ -815,6 +815,7 @@ bool GDALDAASDataset::GetImageMetadata()
{
oGetBufferDict = oGetBufferObj;
}
CPL_IGNORE_RET_VAL(oGetBufferObj);
if (!oGetBufferDict.IsValid())
{
CPLError(CE_Failure, CPLE_AppDefined, "%s missing",
Expand Down Expand Up @@ -995,8 +996,10 @@ void GDALDAASDataset::ReadSRS(const CPLJSONObject &oProperties)
if (oSRSObj.GetType() == CPLJSONObject::Type::Object)
{
bool bError = false;
CPLString osType(GetString(oSRSObj, "type", true, bError));
CPLString osValue(GetString(oSRSObj, "value", true, bError));
const std::string osType(
GetString(oSRSObj, "type", true, bError));
const std::string osValue(
GetString(oSRSObj, "value", true, bError));
// Use urn in priority
if (osType == "urn" && !osValue.empty())
{
Expand Down Expand Up @@ -1193,7 +1196,7 @@ bool GDALDAASDataset::SetupServerSideReprojection(const char *pszTargetSRS)
m_bRequestInGeoreferencedCoordinates = true;
m_osSRSType = "epsg";
m_osSRSValue = std::move(osTargetEPSGCode);
m_oSRS = oSRS;
m_oSRS = std::move(oSRS);
nRasterXSize = nXSize;
nRasterYSize = nYSize;
return true;
Expand Down
8 changes: 4 additions & 4 deletions frmts/ecw/ecwdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1337,19 +1337,19 @@ CPLErr ECWDataset::SetMetadataItem(const char *pszName, const char *pszValue,
if (strcmp(pszName, "PROJ") == 0)
{
bProjCodeChanged = (osNewVal != m_osProjCode);
m_osProjCode = osNewVal;
m_osProjCode = std::move(osNewVal);
bHdrDirty |= bProjCodeChanged;
}
else if (strcmp(pszName, "DATUM") == 0)
{
bDatumCodeChanged |= (osNewVal != m_osDatumCode) ? TRUE : FALSE;
m_osDatumCode = osNewVal;
m_osDatumCode = std::move(osNewVal);
bHdrDirty |= bDatumCodeChanged;
}
else
{
bUnitsCodeChanged |= (osNewVal != m_osUnitsCode) ? TRUE : FALSE;
m_osUnitsCode = osNewVal;
m_osUnitsCode = std::move(osNewVal);
bHdrDirty |= bUnitsCodeChanged;
}
return CE_None;
Expand Down Expand Up @@ -3437,7 +3437,7 @@ void ECWDataset::ECW2WKTProjection()
if (oSRS.importFromERM(psFileInfo->szProjection, psFileInfo->szDatum,
osUnits) == OGRERR_NONE)
{
m_oSRS = oSRS;
m_oSRS = std::move(oSRS);
m_oSRS.SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER);
}

Expand Down
7 changes: 4 additions & 3 deletions frmts/ers/ershdrnode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,8 @@ const char *ERSHdrNode::FindElem(const char *pszPath, int iElem,
ERSHdrNode *ERSHdrNode::FindNode(const char *pszPath)

{
CPLString osPathFirst, osPathRest, osPath = pszPath;
std::string osPathFirst, osPathRest;
const std::string osPath = pszPath;
size_t iDot = osPath.find_first_of('.');
if (iDot == std::string::npos)
{
Expand All @@ -441,12 +442,12 @@ ERSHdrNode *ERSHdrNode::FindNode(const char *pszPath)

for (int i = 0; i < nItemCount; i++)
{
if (EQUAL(osPathFirst, papszItemName[i]))
if (EQUAL(osPathFirst.c_str(), papszItemName[i]))
{
if (papoItemChild[i] != nullptr)
{
if (osPathRest.length() > 0)
return papoItemChild[i]->FindNode(osPathRest);
return papoItemChild[i]->FindNode(osPathRest.c_str());
else
return papoItemChild[i];
}
Expand Down
4 changes: 3 additions & 1 deletion frmts/fits/fitsdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1084,7 +1084,8 @@ void FITSLayer::RunDeferredFieldCreation(const OGRFeature *poFeature)
const char *pszRepeat = m_aosCreationOptions.FetchNameValue(
(CPLString("REPEAT_") + pszFieldName).c_str());

const auto osTFormFromMD = oMapColNameToMetadata[pszFieldName]["TFORM"];
const auto &osTFormFromMD =
oMapColNameToMetadata[pszFieldName]["TFORM"];

// For fields of type list, determine if we can know if it has a fixed
// number of elements
Expand Down Expand Up @@ -1232,6 +1233,7 @@ void FITSLayer::RunDeferredFieldCreation(const OGRFeature *poFeature)
osTForm = oCol.typechar;
}
}
CPL_IGNORE_RET_VAL(osRepeat);
int status = 0;
fits_insert_col(m_poDS->m_hFITS, oCol.iCol, &osTType[0], &osTForm[0],
&status);
Expand Down
6 changes: 3 additions & 3 deletions frmts/gtiff/gt_citation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ void SetLinearUnitCitation(std::map<geokey_t, std::string> &oMapAsciiKeys,
osCitation = "LUnits = ";
osCitation += pszLinearUOMName;
}
oMapAsciiKeys[PCSCitationGeoKey] = osCitation;
oMapAsciiKeys[PCSCitationGeoKey] = std::move(osCitation);
}

/************************************************************************/
Expand All @@ -416,11 +416,11 @@ void SetGeogCSCitation(GTIF *psGTIF,
if (!STARTS_WITH_CI(osOriginalGeogCitation, "GCS Name = "))
{
osCitation = "GCS Name = ";
osCitation += osOriginalGeogCitation;
osCitation += std::move(osOriginalGeogCitation);
}
else
{
osCitation = osOriginalGeogCitation;
osCitation = std::move(osOriginalGeogCitation);
}

if (nDatum == KvUserDefined)
Expand Down
2 changes: 1 addition & 1 deletion frmts/gtiff/gt_wkt_srs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1603,7 +1603,7 @@ OGRSpatialReferenceH GTIFGetOGISDefnAsOSR(GTIF *hGTIF, GTIFDefn *psDefn)
}
if (EQUAL(osGTiffSRSSource.c_str(), "EPSG"))
{
oSRS = oSRSTmp;
oSRS = std::move(oSRSTmp);
}
else if (bPCSCodeValid && EQUAL(osGTiffSRSSource.c_str(), ""))
{
Expand Down
2 changes: 1 addition & 1 deletion frmts/hdf4/hdf4multidim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2622,7 +2622,7 @@ HDF4SDSGroup::GetDimensions(CSLConstList) const
GetFullName(), "Band", std::string(), std::string(),
m_dims[2]->GetSize()));
}
m_dims = newDims;
m_dims = std::move(newDims);

m_varX = GDALMDArrayRegularlySpaced::Create(
GetFullName(), m_dims[1]->GetName(), m_dims[1],
Expand Down
11 changes: 5 additions & 6 deletions frmts/hdf5/bagdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2733,8 +2733,8 @@ GDALDataset *BAGDataset::Open(GDALOpenInfo *poOpenInfo)
BAGDataset *const poDS = new BAGDataset();

poDS->eAccess = poOpenInfo->eAccess;
poDS->m_poRootGroup = poRootGroup;
poDS->m_poSharedResources = poSharedResources;
poDS->m_poRootGroup = std::move(poRootGroup);
poDS->m_poSharedResources = std::move(poSharedResources);

// Extract version as metadata.
CPLString osVersion;
Expand Down Expand Up @@ -2906,8 +2906,7 @@ bool BAGDataset::OpenRaster(GDALOpenInfo *poOpenInfo,
delete poElevBand;
return false;
}
const auto poValuesDims = poValues->GetDimensions();
if (poValuesDims.size() != 1)
if (poValues->GetDimensionCount() != 1)
{
CPLError(CE_Failure, CPLE_AppDefined,
"Wrong dimensions for %s/values",
Expand Down Expand Up @@ -3675,8 +3674,8 @@ GDALDataset *BAGDataset::OpenForCreate(GDALOpenInfo *poOpenInfo, int nXSizeIn,
BAGDataset *const poDS = new BAGDataset();

poDS->eAccess = poOpenInfo->eAccess;
poDS->m_poRootGroup = poRootGroup;
poDS->m_poSharedResources = poSharedResources;
poDS->m_poRootGroup = std::move(poRootGroup);
poDS->m_poSharedResources = std::move(poSharedResources);
poDS->m_aosCreationOptions = papszCreationOptions;

poDS->nRasterXSize = nXSizeIn;
Expand Down
2 changes: 1 addition & 1 deletion frmts/hdf5/hdf5eosparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ void HDF5EOSParser::ParseGridStructure(const CPLJSONObject &oGridStructure)
oDataFieldMetadata.poGridMetadata = poGridMetadataRef;
m_oMapSubdatasetNameToGridDataFieldMetadata
["//HDFEOS/GRIDS/" + osGridName + "/Data_Fields/" +
osDataFieldName] = oDataFieldMetadata;
osDataFieldName] = std::move(oDataFieldMetadata);
}
}
}
Expand Down
Loading

0 comments on commit 307106b

Please sign in to comment.