From db781d6ae662959f6bf72c98d551e0fecbc4f8e5 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Mon, 15 Jan 2024 23:57:00 +0100 Subject: [PATCH] Avoid/fix Coverity performance warnings --- apps/gdal_translate_lib.cpp | 4 +- apps/gdalmdiminfo_lib.cpp | 4 +- apps/gdalmdimtranslate_lib.cpp | 8 +- apps/gdalwarp_lib.cpp | 2 +- apps/ogrinfo_lib.cpp | 4 +- autotest/cpp/test_cpl.cpp | 2 + autotest/cpp/test_ogr_organize_polygons.cpp | 2 +- frmts/aaigrid/aaigriddataset.cpp | 5 +- frmts/adrg/adrgdataset.cpp | 2 +- frmts/adrg/srpdataset.cpp | 4 +- frmts/aigrid/aigdataset.cpp | 2 +- frmts/daas/daasdataset.cpp | 15 ++- frmts/ecw/ecwdataset.cpp | 8 +- frmts/ers/ershdrnode.cpp | 7 +- frmts/fits/fitsdataset.cpp | 4 +- frmts/gtiff/gt_citation.cpp | 6 +- frmts/gtiff/gt_wkt_srs.cpp | 2 +- frmts/hdf4/hdf4multidim.cpp | 2 +- frmts/hdf5/bagdataset.cpp | 11 +- frmts/hdf5/hdf5eosparser.cpp | 2 +- frmts/hdf5/hdf5multidim.cpp | 14 +- frmts/hfa/hfadataset.cpp | 2 +- frmts/hfa/hfaopen.cpp | 4 +- frmts/ilwis/ilwisdataset.cpp | 124 +++++++++--------- frmts/kea/kearat.cpp | 2 +- .../kmlsuperoverlaydataset.cpp | 3 +- frmts/netcdf/netcdfdataset.cpp | 4 +- frmts/netcdf/netcdfdataset.h | 2 +- frmts/netcdf/netcdfmultidim.cpp | 14 +- frmts/nitf/nitfdataset.cpp | 4 +- frmts/ogcapi/gdalogcapidataset.cpp | 21 ++- frmts/pcidsk/sdk/channel/cexternalchannel.cpp | 2 +- frmts/pcidsk/sdk/channel/cexternalchannel.h | 2 +- frmts/pcidsk/sdk/core/cpcidskfile.cpp | 4 +- frmts/pcidsk/sdk/core/cpcidskfile.h | 6 +- frmts/pcidsk/sdk/core/pcidsk_utils.cpp | 5 +- frmts/pcidsk/sdk/core/pcidsk_utils.h | 2 +- frmts/pcidsk/sdk/core/pcidskcreate.cpp | 6 +- frmts/pcidsk/sdk/core/pcidskopen.cpp | 2 +- frmts/pcidsk/sdk/pcidsk.h | 6 +- frmts/pcidsk/sdk/pcidsk_io.h | 2 +- frmts/pcidsk/vsi_pcidsk_io.cpp | 6 +- frmts/pdf/pdfdataset.cpp | 12 +- frmts/pdf/pdfobject.cpp | 2 +- frmts/pds/isis2dataset.cpp | 4 +- frmts/pds/isis3dataset.cpp | 19 ++- frmts/pds/pdsdataset.cpp | 45 +++---- frmts/pds/vicardataset.cpp | 4 +- frmts/plmosaic/plmosaicdataset.cpp | 14 +- frmts/prf/phprfdataset.cpp | 6 +- frmts/raw/byndataset.cpp | 2 +- frmts/raw/dipxdataset.cpp | 2 +- frmts/raw/eirdataset.cpp | 2 +- frmts/raw/hkvdataset.cpp | 4 +- frmts/raw/mffdataset.cpp | 2 +- frmts/raw/ndfdataset.cpp | 2 +- frmts/raw/roipacdataset.cpp | 2 +- frmts/raw/rrasterdataset.cpp | 8 +- frmts/raw/snodasdataset.cpp | 2 +- frmts/rs2/rs2dataset.cpp | 4 +- frmts/safe/safedataset.cpp | 2 +- frmts/sigdem/sigdemdataset.cpp | 2 +- frmts/stacit/stacitdataset.cpp | 2 +- frmts/stacta/stactadataset.cpp | 2 +- frmts/tiledb/tiledbmultidimgroup.cpp | 2 +- frmts/tsx/tsxdataset.cpp | 2 +- frmts/usgsdem/usgsdemdataset.cpp | 2 +- frmts/vrt/vrtmultidim.cpp | 7 +- frmts/wcs/wcsdataset100.cpp | 40 ++---- frmts/wcs/wcsdataset110.cpp | 1 + frmts/wms/minidriver_tiled_wms.cpp | 2 +- frmts/wms/wmsdriver.cpp | 16 ++- frmts/wms/wmsmetadataset.cpp | 4 +- frmts/wms/wmsmetadataset.h | 3 +- frmts/wmts/wmtsdataset.cpp | 3 +- frmts/xyz/xyzdataset.cpp | 2 +- frmts/zarr/zarr_array.cpp | 4 +- frmts/zarr/zarr_attribute.cpp | 2 +- frmts/zarr/zarr_v2_array.cpp | 4 +- frmts/zarr/zarr_v2_group.cpp | 2 +- frmts/zarr/zarr_v3_codec.cpp | 2 +- frmts/zarr/zarrdriver.cpp | 11 +- fuzzers/gdal_fuzzer.cpp | 2 +- gcore/gdaljp2metadata.cpp | 14 +- gcore/gdaljp2structure.cpp | 8 +- gcore/gdalmultidim.cpp | 25 ++-- gcore/gdalmultidim_gridded.cpp | 2 +- gcore/gdalpython.cpp | 3 +- gcore/gdalrasterband.cpp | 2 +- gcore/mdreader/reader_eros.cpp | 19 +-- gcore/mdreader/reader_landsat.cpp | 6 +- gcore/mdreader/reader_orb_view.cpp | 6 +- gcore/mdreader/reader_pleiades.cpp | 12 +- gcore/mdreader/reader_spot.cpp | 12 +- gnm/gnm_frmts/file/gnmfilenetwork.cpp | 2 +- gnm/gnmgraph.cpp | 2 +- ogr/ogrsf_frmts/arrow/ogrfeatherlayer.cpp | 2 +- .../arrow_common/ograrrowlayer.hpp | 4 +- .../arrow_common/ograrrowwriterlayer.hpp | 10 +- ogr/ogrsf_frmts/cad/libopencad/dwg/r2000.cpp | 16 +-- ogr/ogrsf_frmts/csv/ogrcsvlayer.cpp | 3 +- ogr/ogrsf_frmts/dxf/ogrdxf_leader.cpp | 2 +- ogr/ogrsf_frmts/dxf/ogrdxfdatasource.cpp | 8 +- ogr/ogrsf_frmts/dxf/ogrdxflayer.cpp | 8 +- ogr/ogrsf_frmts/dxf/ogrdxfwriterlayer.cpp | 2 +- .../edigeo/ogredigeodatasource.cpp | 4 +- ogr/ogrsf_frmts/filegdb/FGdbDatasource.cpp | 2 +- ogr/ogrsf_frmts/filegdb/FGdbDriver.cpp | 3 +- ogr/ogrsf_frmts/filegdb/FGdbLayer.cpp | 2 +- ogr/ogrsf_frmts/generic/ogreditablelayer.cpp | 6 +- ogr/ogrsf_frmts/generic/ogrlayerarrow.cpp | 2 +- ogr/ogrsf_frmts/gmlas/ogrgmlasconf.cpp | 5 +- ogr/ogrsf_frmts/gmlas/ogrgmlasdatasource.cpp | 24 ++-- ogr/ogrsf_frmts/gmlas/ogrgmlaslayer.cpp | 10 +- ogr/ogrsf_frmts/gmlas/ogrgmlasreader.cpp | 4 +- .../gmlas/ogrgmlasschemaanalyzer.cpp | 2 +- ogr/ogrsf_frmts/gmlas/ogrgmlaswriter.cpp | 15 ++- .../gmlas/ogrgmlasxpatchmatcher.cpp | 2 +- .../gpkg/ogrgeopackagedatasource.cpp | 3 +- .../gpkg/ogrgeopackagetablelayer.cpp | 8 +- ogr/ogrsf_frmts/gpx/ogrgpxdatasource.cpp | 7 +- ogr/ogrsf_frmts/hana/ogrhanadatasource.cpp | 2 +- ogr/ogrsf_frmts/hana/ogrhanafeaturereader.cpp | 2 +- ogr/ogrsf_frmts/hana/ogrhanatablelayer.cpp | 2 +- .../libkml/ogrlibkmldatasource.cpp | 36 ++--- ogr/ogrsf_frmts/libkml/ogrlibkmllayer.cpp | 2 +- ogr/ogrsf_frmts/libkml/ogrlibkmlstyle.cpp | 4 +- ogr/ogrsf_frmts/mem/ogrmemdatasource.cpp | 4 +- ogr/ogrsf_frmts/mvt/ogrmvtdataset.cpp | 8 +- ogr/ogrsf_frmts/openfilegdb/filegdbtable.cpp | 4 +- .../openfilegdb/gdalopenfilegdbrasterband.cpp | 2 +- .../ogropenfilegdbdatasource_write.cpp | 4 +- ogr/ogrsf_frmts/osm/ogrosmdatasource.cpp | 9 +- .../parquet/ogrparquetdatasetlayer.cpp | 2 +- ogr/ogrsf_frmts/parquet/ogrparquetdriver.cpp | 6 +- ogr/ogrsf_frmts/parquet/ogrparquetlayer.cpp | 4 +- ogr/ogrsf_frmts/pgeo/ogrpgeodatasource.cpp | 2 +- .../pmtiles/ogrpmtilesfrommbtiles.cpp | 5 +- ogr/ogrsf_frmts/shape/ogrshapedatasource.cpp | 2 +- ogr/ogrsf_frmts/shape/ogrshapelayer.cpp | 10 +- ogr/ogrsf_frmts/sosi/ogrsosilayer.cpp | 5 +- ogr/ogrsf_frmts/sxf/ogrsxflayer.cpp | 4 +- ogr/ogrsf_frmts/vdv/ogrvdvdatasource.cpp | 2 +- ogr/ogrsf_frmts/wfs/ogroapifdriver.cpp | 14 +- ogr/ogrsf_frmts/wfs/ogrwfslayer.cpp | 8 +- port/cpl_vsi_mem.cpp | 3 +- port/cpl_vsil_adls.cpp | 4 +- port/cpl_vsil_az.cpp | 4 +- port/cpl_vsil_crypt.cpp | 1 + port/cpl_vsil_curl.cpp | 4 +- port/cpl_vsil_gzip.cpp | 2 +- port/cpl_vsil_s3.cpp | 10 +- port/cplstring.cpp | 22 ++-- 153 files changed, 527 insertions(+), 521 deletions(-) diff --git a/apps/gdal_translate_lib.cpp b/apps/gdal_translate_lib.cpp index c8018d0cab55..3f89858554cf 100644 --- a/apps/gdal_translate_lib.cpp +++ b/apps/gdal_translate_lib.cpp @@ -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); @@ -1641,7 +1641,7 @@ GDALDatasetH GDALTranslate(const char *pszDest, GDALDatasetH hSrcDataset, fabs(adfSrcGeoTransform[5] / adfDstGeoTransform[5]); } - const auto adfSrcWinOri = psOptions->adfSrcWin; + const std::array adfSrcWinOri(psOptions->adfSrcWin); const double dfRatioX = poSrcDS->GetRasterXSize() == 0 ? 1.0 diff --git a/apps/gdalmdiminfo_lib.cpp b/apps/gdalmdiminfo_lib.cpp index 386ba525cf02..ad9e1a05ae4b 100644 --- a/apps/gdalmdiminfo_lib.cpp +++ b/apps/gdalmdiminfo_lib.cpp @@ -537,7 +537,7 @@ static void DumpArrayRec(std::shared_ptr 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 &abyTmp, @@ -805,7 +805,7 @@ static void DumpArray(const std::shared_ptr &rootGroup, DumpAttrs(attrs, serializer, psOptions); } - auto unit = array->GetUnit(); + const auto &unit = array->GetUnit(); if (!unit.empty()) { serializer.AddObjKey("unit"); diff --git a/apps/gdalmdimtranslate_lib.cpp b/apps/gdalmdimtranslate_lib.cpp index cc9c84d959ec..36ca2852f8fd 100644 --- a/apps/gdalmdimtranslate_lib.cpp +++ b/apps/gdalmdimtranslate_lib.cpp @@ -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) @@ -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 && @@ -1230,7 +1230,7 @@ GetGroup(const std::shared_ptr &poRootGroup, aosTokens[i]); return nullptr; } - poCurGroup = poCurGroupNew; + poCurGroup = std::move(poCurGroupNew); } return poCurGroup; } @@ -1560,7 +1560,7 @@ CopyToNonMultiDimensionalDriver(GDALDriver *poDriver, const char *pszDest, "output to non-multidimensional driver"); return nullptr; } - srcArray = tmpArray; + srcArray = std::move(tmpArray); } } } diff --git a/apps/gdalwarp_lib.cpp b/apps/gdalwarp_lib.cpp index a99712970c8f..e0670819452a 100644 --- a/apps/gdalwarp_lib.cpp +++ b/apps/gdalwarp_lib.cpp @@ -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; diff --git a/apps/ogrinfo_lib.cpp b/apps/ogrinfo_lib.cpp index d68e3c8cee66..ed1785c22636 100644 --- a/apps/ogrinfo_lib.cpp +++ b/apps/ogrinfo_lib.cpp @@ -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, @@ -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++) diff --git a/autotest/cpp/test_cpl.cpp b/autotest/cpp/test_cpl.cpp index 25dc40a3b83e..c833e87483ac 100644 --- a/autotest/cpp/test_cpl.cpp +++ b/autotest/cpp/test_cpl.cpp @@ -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; diff --git a/autotest/cpp/test_ogr_organize_polygons.cpp b/autotest/cpp/test_ogr_organize_polygons.cpp index eaba36bd9b28..e4b1ccb51042 100644 --- a/autotest/cpp/test_ogr_organize_polygons.cpp +++ b/autotest/cpp/test_ogr_organize_polygons.cpp @@ -65,7 +65,7 @@ class OrganizePolygonsTest : public testing::TestWithParam INSTANTIATE_TEST_SUITE_P( test_gdal, OrganizePolygonsTest, ::testing::Values("DEFAULT", "ONLY_CCW", "SKIP"), - [](const ::testing::TestParamInfo ¶m_info) + [](const ::testing::TestParamInfo ¶m_info) -> std::string { return param_info.param; }); TEST_P(OrganizePolygonsTest, EmptyInputVector) diff --git a/frmts/aaigrid/aaigriddataset.cpp b/frmts/aaigrid/aaigriddataset.cpp index 4f407c5f7659..5cd7e8e1590b 100644 --- a/frmts/aaigrid/aaigriddataset.cpp +++ b/frmts/aaigrid/aaigriddataset.cpp @@ -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") @@ -1251,7 +1250,7 @@ GDALDataset *AAIGDataset::CommonOpen(GDALOpenInfo *poOpenInfo, poDS->adfGeoTransform[5] /= 3600.0; } - poDS->m_oSRS = oSRS; + poDS->m_oSRS = std::move(oSRS); } } diff --git a/frmts/adrg/adrgdataset.cpp b/frmts/adrg/adrgdataset.cpp index bb2935dd5b55..b64abaa9bb11 100644 --- a/frmts/adrg/adrgdataset.cpp +++ b/frmts/adrg/adrgdataset.cpp @@ -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) diff --git a/frmts/adrg/srpdataset.cpp b/frmts/adrg/srpdataset.cpp index 8c8295b6e804..b5f75aad8d51 100644 --- a/frmts/adrg/srpdataset.cpp +++ b/frmts/adrg/srpdataset.cpp @@ -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) diff --git a/frmts/aigrid/aigdataset.cpp b/frmts/aigrid/aigdataset.cpp index ede0a42e16ac..4c04adc7a8d2 100644 --- a/frmts/aigrid/aigdataset.cpp +++ b/frmts/aigrid/aigdataset.cpp @@ -745,7 +745,7 @@ GDALDataset *AIGDataset::Open(GDALOpenInfo *poOpenInfo) psInfo->dfCellSizeY /= 3600.0; } - poDS->m_oSRS = oSRS; + poDS->m_oSRS = std::move(oSRS); } } diff --git a/frmts/daas/daasdataset.cpp b/frmts/daas/daasdataset.cpp index 9d2912beb29e..07b2a09b0916 100644 --- a/frmts/daas/daasdataset.cpp +++ b/frmts/daas/daasdataset.cpp @@ -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( @@ -815,6 +815,7 @@ bool GDALDAASDataset::GetImageMetadata() { oGetBufferDict = oGetBufferObj; } + CPL_IGNORE_RET_VAL(oGetBufferObj); if (!oGetBufferDict.IsValid()) { CPLError(CE_Failure, CPLE_AppDefined, "%s missing", @@ -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()) { @@ -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; diff --git a/frmts/ecw/ecwdataset.cpp b/frmts/ecw/ecwdataset.cpp index c98715d847a6..84c59be0f05b 100644 --- a/frmts/ecw/ecwdataset.cpp +++ b/frmts/ecw/ecwdataset.cpp @@ -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; @@ -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); } diff --git a/frmts/ers/ershdrnode.cpp b/frmts/ers/ershdrnode.cpp index 8809dc4d2aa8..3fe2e6b6de04 100644 --- a/frmts/ers/ershdrnode.cpp +++ b/frmts/ers/ershdrnode.cpp @@ -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) { @@ -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]; } diff --git a/frmts/fits/fitsdataset.cpp b/frmts/fits/fitsdataset.cpp index 01056ca4776c..6c717f76bf02 100644 --- a/frmts/fits/fitsdataset.cpp +++ b/frmts/fits/fitsdataset.cpp @@ -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 @@ -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); diff --git a/frmts/gtiff/gt_citation.cpp b/frmts/gtiff/gt_citation.cpp index d85cae8d82c0..df1100a6b16d 100644 --- a/frmts/gtiff/gt_citation.cpp +++ b/frmts/gtiff/gt_citation.cpp @@ -389,7 +389,7 @@ void SetLinearUnitCitation(std::map &oMapAsciiKeys, osCitation = "LUnits = "; osCitation += pszLinearUOMName; } - oMapAsciiKeys[PCSCitationGeoKey] = osCitation; + oMapAsciiKeys[PCSCitationGeoKey] = std::move(osCitation); } /************************************************************************/ @@ -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) diff --git a/frmts/gtiff/gt_wkt_srs.cpp b/frmts/gtiff/gt_wkt_srs.cpp index cd5b63a18e80..9492d79a4df7 100644 --- a/frmts/gtiff/gt_wkt_srs.cpp +++ b/frmts/gtiff/gt_wkt_srs.cpp @@ -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(), "")) { diff --git a/frmts/hdf4/hdf4multidim.cpp b/frmts/hdf4/hdf4multidim.cpp index e1c84535ef5e..526fc61795d5 100644 --- a/frmts/hdf4/hdf4multidim.cpp +++ b/frmts/hdf4/hdf4multidim.cpp @@ -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], diff --git a/frmts/hdf5/bagdataset.cpp b/frmts/hdf5/bagdataset.cpp index 4f19af44b6ef..d15f9dc73277 100644 --- a/frmts/hdf5/bagdataset.cpp +++ b/frmts/hdf5/bagdataset.cpp @@ -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; @@ -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", @@ -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; diff --git a/frmts/hdf5/hdf5eosparser.cpp b/frmts/hdf5/hdf5eosparser.cpp index f833cd950aad..c5996b222dde 100644 --- a/frmts/hdf5/hdf5eosparser.cpp +++ b/frmts/hdf5/hdf5eosparser.cpp @@ -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); } } } diff --git a/frmts/hdf5/hdf5multidim.cpp b/frmts/hdf5/hdf5multidim.cpp index 8e619d030cc9..d7a2a4394943 100644 --- a/frmts/hdf5/hdf5multidim.cpp +++ b/frmts/hdf5/hdf5multidim.cpp @@ -1530,7 +1530,7 @@ void HDF5Array::InstantiateDimensions(const std::string &osParentName, auto nPos = osDimName.rfind('/'); if (nPos != std::string::npos) { - std::string osDimParentName(osDimName.substr(0, nPos)); + const std::string osDimParentName(osDimName.substr(0, nPos)); osDimName = osDimName.substr(nPos + 1); m_dims.emplace_back(std::make_shared( @@ -2210,12 +2210,12 @@ static void CopyValue(const GByte *pabySrcBuffer, hid_t hSrcDataType, { const unsigned iSrc = mapDstCompsToSrcComps[iDst]; auto hMemberType = H5Tget_member_type(hSrcDataType, iSrc); - const auto mapDstSubCompsToSrcSubComps = + const std::vector mapDstSubCompsToSrcSubComps( (H5Tget_class(hMemberType) == H5T_COMPOUND && comps[iDst]->GetType().GetClass() == GEDTC_COMPOUND) ? CreateMapTargetComponentsToSrc(hMemberType, comps[iDst]->GetType()) - : std::vector(); + : std::vector()); CopyValue(pabySrcBuffer + H5Tget_member_offset(hSrcDataType, iSrc), hMemberType, pabyDstBuffer + comps[iDst]->GetOffset(), @@ -2255,11 +2255,11 @@ static void CopyToFinalBuffer(void *pDstBuffer, const void *pTemp, size_t nDims, const GByte *pabySrcBuffer = static_cast(pTemp); pabyDstBufferStack[0] = static_cast(pDstBuffer); size_t iDim = 0; - const auto mapDstCompsToSrcComps = + const std::vector mapDstCompsToSrcComps( (H5Tget_class(hSrcDataType) == H5T_COMPOUND && bufferDataType.GetClass() == GEDTC_COMPOUND) ? CreateMapTargetComponentsToSrc(hSrcDataType, bufferDataType) - : std::vector(); + : std::vector()); bool bFastCopyOfCompoundToSingleComponentCompound = false; GDALDataType eSrcTypeComp = GDT_Unknown; @@ -2545,11 +2545,11 @@ static void CopyAllAttrValuesInto(size_t nDims, const GUInt64 *arrayStartIdx, std::vector anStackCount(nDims); std::vector pabySrcBufferStack(nDims + 1); std::vector pabyDstBufferStack(nDims + 1); - const auto mapDstCompsToSrcComps = + const std::vector mapDstCompsToSrcComps( (H5Tget_class(hSrcBufferType) == H5T_COMPOUND && bufferDataType.GetClass() == GEDTC_COMPOUND) ? CreateMapTargetComponentsToSrc(hSrcBufferType, bufferDataType) - : std::vector(); + : std::vector()); pabySrcBufferStack[0] = static_cast(pabySrcBuffer); if (nDims > 0) diff --git a/frmts/hfa/hfadataset.cpp b/frmts/hfa/hfadataset.cpp index 5cd0fe219981..6b573ee2f26c 100644 --- a/frmts/hfa/hfadataset.cpp +++ b/frmts/hfa/hfadataset.cpp @@ -4218,7 +4218,7 @@ CPLErr HFADataset::ReadProjection() "configuration option to NO.", pszProjName); } - m_oSRS = oSRSFromPE; + m_oSRS = std::move(oSRSFromPE); } CPLFree(pszPE_COORDSYS); return m_oSRS.IsEmpty() ? CE_Failure : CE_None; diff --git a/frmts/hfa/hfaopen.cpp b/frmts/hfa/hfaopen.cpp index cac8b7a9c1ca..e9890058096c 100644 --- a/frmts/hfa/hfaopen.cpp +++ b/frmts/hfa/hfaopen.cpp @@ -3807,9 +3807,9 @@ CPLErr HFARenameReferences(HFAHandle hHFA, const char *pszNewBase, // Update the filename. if (strncmp(osFileName, pszOldBase, strlen(pszOldBase)) == 0) { - CPLString osNew = pszNewBase; + std::string osNew = pszNewBase; osNew += osFileName.c_str() + strlen(pszOldBase); - osFileName = osNew; + osFileName = std::move(osNew); } // Grow the node if needed. diff --git a/frmts/ilwis/ilwisdataset.cpp b/frmts/ilwis/ilwisdataset.cpp index b27a80403922..ff37c1a8785a 100644 --- a/frmts/ilwis/ilwisdataset.cpp +++ b/frmts/ilwis/ilwisdataset.cpp @@ -509,10 +509,10 @@ void ILWISDataset::CollectTransformCoef(std::string &pszRefName) if (!georef.empty() && !EQUAL(georef.c_str(), "none")) { // Form the geo-referencing name - std::string pszBaseName = std::string(CPLGetBasename(georef.c_str())); - std::string pszPath = std::string(CPLGetPath(osFileName)); + std::string osBaseName = std::string(CPLGetBasename(georef.c_str())); + std::string osPath = std::string(CPLGetPath(osFileName)); pszRefName = std::string( - CPLFormFilename(pszPath.c_str(), pszBaseName.c_str(), "grf")); + CPLFormFilename(osPath.c_str(), osBaseName.c_str(), "grf")); // Check the geo-reference type,support for the GeoRefCorners only std::string georeftype = ReadElement("GeoRef", "Type", pszRefName); @@ -708,7 +708,7 @@ GDALDataset *ILWISDataset::Open(GDALOpenInfo *poOpenInfo) if (ilwistype.empty()) return nullptr; - std::string sFileType; // map or map list + const char *pszFileType = ""; // map or map list int iBandCount; std::string mapsize; const std::string maptype = @@ -720,7 +720,7 @@ GDALDataset *ILWISDataset::Open(GDALOpenInfo *poOpenInfo) // Verify whether it is a map list or a map if (EQUAL(ilwistype.c_str(), "MapList")) { - sFileType = std::string("MapList"); + pszFileType = "MapList"; std::string sMaps = ReadElement("MapList", "Maps", poOpenInfo->pszFilename); iBandCount = atoi(sMaps.c_str()); @@ -760,7 +760,7 @@ GDALDataset *ILWISDataset::Open(GDALOpenInfo *poOpenInfo) else if (EQUAL(ilwistype.c_str(), "BaseMap") && EQUAL(maptype.c_str(), "Map")) { - sFileType = "Map"; + pszFileType = "Map"; iBandCount = 1; mapsize = ReadElement("Map", "Size", poOpenInfo->pszFilename); // std::string sMapType = ReadElement("Map", "Type", @@ -806,7 +806,7 @@ GDALDataset *ILWISDataset::Open(GDALOpenInfo *poOpenInfo) poDS->nRasterXSize = Col; poDS->nRasterYSize = Row; poDS->osFileName = poOpenInfo->pszFilename; - poDS->pszFileType = sFileType; + poDS->pszFileType = pszFileType; /* -------------------------------------------------------------------- */ /* Create band information objects. */ /* -------------------------------------------------------------------- */ @@ -841,11 +841,11 @@ GDALDataset *ILWISDataset::Open(GDALOpenInfo *poOpenInfo) if (!(STARTS_WITH_CI(csy.c_str(), "latlon.csy")) && !(STARTS_WITH_CI(csy.c_str(), "LatlonWGS84.csy"))) { - std::string pszBaseName = + std::string osBaseName = std::string(CPLGetBasename(csy.c_str())); - std::string pszPath = std::string(CPLGetPath(poDS->osFileName)); - csy = std::string(CPLFormFilename(pszPath.c_str(), - pszBaseName.c_str(), "csy")); + std::string osPath = std::string(CPLGetPath(poDS->osFileName)); + csy = std::string( + CPLFormFilename(osPath.c_str(), osBaseName.c_str(), "csy")); pszProj = ReadElement("CoordSystem", "Type", csy); if (pszProj.empty()) // default to projection pszProj = "Projection"; @@ -933,15 +933,15 @@ GDALDataset *ILWISDataset::Create(const char *pszFilename, int nXSize, EQUAL(sStoreType.c_str(), "float")) stepsize = 0; - const std::string pszBaseName = std::string(CPLGetBasename(pszFilename)); - const std::string pszPath = std::string(CPLGetPath(pszFilename)); + const std::string osBaseName = std::string(CPLGetBasename(pszFilename)); + const std::string osPath = std::string(CPLGetPath(pszFilename)); /* -------------------------------------------------------------------- */ /* Write out object definition file for each band */ /* -------------------------------------------------------------------- */ std::string pszODFName; std::string pszDataBaseName; - std::string pszFileName; + std::string osFilename; char strsize[45]; snprintf(strsize, sizeof(strsize), "%d %d", nYSize, nXSize); @@ -951,16 +951,14 @@ GDALDataset *ILWISDataset::Create(const char *pszFilename, int nXSize, if (nBandsIn == 1) { pszODFName = std::string( - CPLFormFilename(pszPath.c_str(), pszBaseName.c_str(), "mpr")); - pszDataBaseName = pszBaseName; - pszFileName = - CPLFormFilename(pszPath.c_str(), pszBaseName.c_str(), "mpr"); + CPLFormFilename(osPath.c_str(), osBaseName.c_str(), "mpr")); + pszDataBaseName = osBaseName; + osFilename = CPLFormFilename(osPath.c_str(), osBaseName.c_str(), "mpr"); } else { - pszFileName = - CPLFormFilename(pszPath.c_str(), pszBaseName.c_str(), "mpl"); - auto iniFile = new IniFile(std::string(pszFileName)); + osFilename = CPLFormFilename(osPath.c_str(), osBaseName.c_str(), "mpl"); + auto iniFile = new IniFile(std::string(osFilename)); iniFile->SetKeyValue("Ilwis", "Type", "MapList"); iniFile->SetKeyValue("MapList", "GeoRef", "none.grf"); iniFile->SetKeyValue("MapList", "Size", std::string(strsize)); @@ -974,14 +972,14 @@ GDALDataset *ILWISDataset::Create(const char *pszFilename, int nXSize, { char szBandName[100]; snprintf(szBandName, sizeof(szBandName), "%s_band_%d", - pszBaseName.c_str(), iBand + 1); + osBaseName.c_str(), iBand + 1); pszODFName = std::string(szBandName) + ".mpr"; pszDataBaseName = std::string(szBandName); snprintf(szBandName, sizeof(szBandName), "Map%d", iBand); globalFile->SetKeyValue("MapList", std::string(szBandName), pszODFName); - pszODFName = CPLFormFilename(pszPath.c_str(), - pszDataBaseName.c_str(), "mpr"); + pszODFName = + CPLFormFilename(osPath.c_str(), pszDataBaseName.c_str(), "mpr"); } /* -------------------------------------------------------------------- */ @@ -1043,8 +1041,9 @@ GDALDataset *ILWISDataset::Create(const char *pszFilename, int nXSize, poDS->eAccess = GA_Update; poDS->bNewDataset = TRUE; poDS->SetDescription(pszFilename); - poDS->osFileName = pszFileName; - poDS->pszIlwFileName = std::string(pszFileName); + poDS->osFileName = osFilename; + poDS->pszIlwFileName = osFilename; + CPL_IGNORE_RET_VAL(osFilename); if (nBandsIn == 1) poDS->pszFileType = "Map"; else @@ -1059,8 +1058,7 @@ GDALDataset *ILWISDataset::Create(const char *pszFilename, int nXSize, std::string sBandName; if (poDS->nBands > 1) { - sBandName = - CPLSPrintf("%s_band_%d.mpr", pszBaseName.c_str(), iBand); + sBandName = CPLSPrintf("%s_band_%d.mpr", osBaseName.c_str(), iBand); } poDS->SetBand(iBand, new ILWISRasterBand(poDS, iBand, sBandName)); } @@ -1105,8 +1103,8 @@ GDALDataset *ILWISDataset::CreateCopy(const char *pszFilename, if (poDS == nullptr) return nullptr; - const std::string pszBaseName = std::string(CPLGetBasename(pszFilename)); - const std::string pszPath = std::string(CPLGetPath(pszFilename)); + const std::string osBaseName = std::string(CPLGetBasename(pszFilename)); + const std::string osPath = std::string(CPLGetPath(pszFilename)); /* -------------------------------------------------------------------- */ /* Copy and geo-transform and projection information. */ @@ -1123,7 +1121,7 @@ GDALDataset *ILWISDataset::CreateCopy(const char *pszFilename, { poDS->SetGeoTransform(adfGeoTransform); if (adfGeoTransform[2] == 0.0 && adfGeoTransform[4] == 0.0) - georef = pszBaseName + ".grf"; + georef = osBaseName + ".grf"; } const OGRSpatialReference *poSrcSRS = poSrcDS->GetSpatialRef(); @@ -1168,16 +1166,16 @@ GDALDataset *ILWISDataset::CreateCopy(const char *pszFilename, if (nBands == 1) { pszODFName = std::string( - CPLFormFilename(pszPath.c_str(), pszBaseName.c_str(), "mpr")); - // pszDataBaseName = pszBaseName; + CPLFormFilename(osPath.c_str(), osBaseName.c_str(), "mpr")); + // pszDataBaseName = osBaseName; } else { char szName[100]; - snprintf(szName, sizeof(szName), "%s_band_%d", pszBaseName.c_str(), + snprintf(szName, sizeof(szName), "%s_band_%d", osBaseName.c_str(), iBand + 1); pszODFName = - std::string(CPLFormFilename(pszPath.c_str(), szName, "mpr")); + std::string(CPLFormFilename(osPath.c_str(), szName, "mpr")); // pszDataBaseName = std::string(szName); } /* -------------------------------------------------------------------- @@ -1491,42 +1489,42 @@ CPLErr ILWISRasterBand::GetILWISInfo(const std::string &pszFileName) // may not be installed, and even if it is, we don't know where (thus it is // useless to attempt to read a system-domain-file). - std::string domName = ReadElement("BaseMap", "Domain", pszFileName.c_str()); - std::string pszBaseName = std::string(CPLGetBasename(domName.c_str())); - std::string pszPath = std::string(CPLGetPath(pszFileName.c_str())); + const std::string domName = + ReadElement("BaseMap", "Domain", pszFileName.c_str()); + const std::string osBaseName = std::string(CPLGetBasename(domName.c_str())); + const std::string osPath = std::string(CPLGetPath(pszFileName.c_str())); // Check against all "system-domains" - if (EQUAL(pszBaseName.c_str(), + if (EQUAL(osBaseName.c_str(), "value") // is it a system domain with Type=DomainValue? - || EQUAL(pszBaseName.c_str(), "count") || - EQUAL(pszBaseName.c_str(), "distance") || - EQUAL(pszBaseName.c_str(), "min1to1") || - EQUAL(pszBaseName.c_str(), "nilto1") || - EQUAL(pszBaseName.c_str(), "noaa") || - EQUAL(pszBaseName.c_str(), "perc") || - EQUAL(pszBaseName.c_str(), "radar")) + || EQUAL(osBaseName.c_str(), "count") || + EQUAL(osBaseName.c_str(), "distance") || + EQUAL(osBaseName.c_str(), "min1to1") || + EQUAL(osBaseName.c_str(), "nilto1") || + EQUAL(osBaseName.c_str(), "noaa") || + EQUAL(osBaseName.c_str(), "perc") || EQUAL(osBaseName.c_str(), "radar")) { ReadValueDomainProperties(pszFileName); } - else if (EQUAL(pszBaseName.c_str(), "bool") || - EQUAL(pszBaseName.c_str(), "byte") || - EQUAL(pszBaseName.c_str(), "bit") || - EQUAL(pszBaseName.c_str(), "image") || - EQUAL(pszBaseName.c_str(), "colorcmp") || - EQUAL(pszBaseName.c_str(), "flowdirection") || - EQUAL(pszBaseName.c_str(), "hortonratio") || - EQUAL(pszBaseName.c_str(), "yesno")) + else if (EQUAL(osBaseName.c_str(), "bool") || + EQUAL(osBaseName.c_str(), "byte") || + EQUAL(osBaseName.c_str(), "bit") || + EQUAL(osBaseName.c_str(), "image") || + EQUAL(osBaseName.c_str(), "colorcmp") || + EQUAL(osBaseName.c_str(), "flowdirection") || + EQUAL(osBaseName.c_str(), "hortonratio") || + EQUAL(osBaseName.c_str(), "yesno")) { eDataType = GDT_Byte; - if (EQUAL(pszBaseName.c_str(), "image") || - EQUAL(pszBaseName.c_str(), "colorcmp")) - psInfo.stDomain = pszBaseName; + if (EQUAL(osBaseName.c_str(), "image") || + EQUAL(osBaseName.c_str(), "colorcmp")) + psInfo.stDomain = osBaseName; } - else if (EQUAL(pszBaseName.c_str(), "color") || - EQUAL(pszBaseName.c_str(), "none") || - EQUAL(pszBaseName.c_str(), "coordbuf") || - EQUAL(pszBaseName.c_str(), "binary") || - EQUAL(pszBaseName.c_str(), "string")) + else if (EQUAL(osBaseName.c_str(), "color") || + EQUAL(osBaseName.c_str(), "none") || + EQUAL(osBaseName.c_str(), "coordbuf") || + EQUAL(osBaseName.c_str(), "binary") || + EQUAL(osBaseName.c_str(), "string")) { CPLError(CE_Failure, CPLE_AppDefined, "Unsupported ILWIS domain type."); return CE_Failure; @@ -1536,7 +1534,7 @@ CPLErr ILWISRasterBand::GetILWISInfo(const std::string &pszFileName) // No match found. Assume it is a self-created domain. Read its type and // decide the GDAL type. std::string pszDomainFileName = std::string( - CPLFormFilename(pszPath.c_str(), pszBaseName.c_str(), "dom")); + CPLFormFilename(osPath.c_str(), osBaseName.c_str(), "dom")); std::string domType = ReadElement("Domain", "Type", pszDomainFileName.c_str()); if (EQUAL(domType.c_str(), diff --git a/frmts/kea/kearat.cpp b/frmts/kea/kearat.cpp index 301af2954929..24d92ff39b98 100644 --- a/frmts/kea/kearat.cpp +++ b/frmts/kea/kearat.cpp @@ -907,7 +907,7 @@ CPLErr KEARasterAttributeTable::CreateColumn(const char *pszFieldName, }*/ CPLMutexHolderD(&m_hMutex); - std::string strUsage = "Generic"; + const char *strUsage = "Generic"; switch (eFieldUsage) { case GFU_PixelCount: diff --git a/frmts/kmlsuperoverlay/kmlsuperoverlaydataset.cpp b/frmts/kmlsuperoverlay/kmlsuperoverlaydataset.cpp index 548a942ae8e0..8803901c4919 100644 --- a/frmts/kmlsuperoverlay/kmlsuperoverlaydataset.cpp +++ b/frmts/kmlsuperoverlay/kmlsuperoverlaydataset.cpp @@ -1443,6 +1443,7 @@ CPLErr KmlSuperOverlayReadDataset::IRasterIO( 4 * sizeof(double)); aosImages.push_back(oImageDesc); } + CPL_IGNORE_RET_VAL(osSubFilename); } } psIter = psIter->psNext; @@ -2451,7 +2452,7 @@ GDALDataset *KmlSingleDocRasterDataset::Open(const char *pszFilename, poDS->nRasterYSize = nYSize; poDS->nLevel = (int)aosDescs.size(); poDS->nTileSize = nTileSize; - poDS->osDirname = osDirname; + poDS->osDirname = std::move(osDirname); poDS->osNominalExt = oDesc.szExtI; memcpy(poDS->adfGlobalExtents, adfGlobalExtents, 4 * sizeof(double)); poDS->adfGeoTransform[0] = adfGlobalExtents[0]; diff --git a/frmts/netcdf/netcdfdataset.cpp b/frmts/netcdf/netcdfdataset.cpp index c0d383f67c4d..bf409cad22f1 100644 --- a/frmts/netcdf/netcdfdataset.cpp +++ b/frmts/netcdf/netcdfdataset.cpp @@ -4800,7 +4800,7 @@ void netCDFDataset::SetProjectionFromVar( SET_FROM_USER_INPUT_LIMITATIONS_get()) == OGRERR_NONE && AreSRSEqualThroughProj4String(oSRS, oSRSFromGBCRS)) { - oSRS = oSRSFromGBCRS; + oSRS = std::move(oSRSFromGBCRS); SetSpatialRefNoUpdate(&oSRS); } } @@ -13307,7 +13307,7 @@ CPLErr netCDFDataset::FilterVars( // Create vector layers from given potentially identified vector variables // resulting from the scanning of a NetCDF (or group) ID. CPLErr netCDFDataset::CreateGrpVectorLayers( - int nCdfId, CPLString osFeatureType, + int nCdfId, const CPLString &osFeatureType, const std::vector &anPotentialVectorVarID, const std::map &oMapDimIdToCount, int nVarXId, int nVarYId, int nVarZId, int nProfileDimId, int nParentIndexVarID, bool bKeepRasters) diff --git a/frmts/netcdf/netcdfdataset.h b/frmts/netcdf/netcdfdataset.h index ccd087e9dbec..58dcbca29cb6 100644 --- a/frmts/netcdf/netcdfdataset.h +++ b/frmts/netcdf/netcdfdataset.h @@ -910,7 +910,7 @@ class netCDFDataset final : public GDALPamDataset // value is (groupId, varId) std::map, std::vector>> &oMap2DDimsToGroupAndVar); - CPLErr CreateGrpVectorLayers(int nCdfId, CPLString osFeatureType, + CPLErr CreateGrpVectorLayers(int nCdfId, const CPLString &osFeatureType, const std::vector &anPotentialVectorVarID, const std::map &oMapDimIdToCount, int nVarXId, int nVarYId, int nVarZId, diff --git a/frmts/netcdf/netcdfmultidim.cpp b/frmts/netcdf/netcdfmultidim.cpp index 73495d01f11f..6ab2bc786d0d 100644 --- a/frmts/netcdf/netcdfmultidim.cpp +++ b/frmts/netcdf/netcdfmultidim.cpp @@ -1265,10 +1265,10 @@ netCDFGroup::GetGroupNames(CSLConstList papszOptions) const for (const auto &osArrayName : GetMDArrayNames(nullptr)) { const auto poArray = OpenMDArray(osArrayName, nullptr); - const auto apoDims = poArray->GetDimensions(); + const auto &apoDims = poArray->GetDimensions(); if (apoDims.size() == 1) { - const auto osDimName = apoDims[0]->GetName(); + const auto &osDimName = apoDims[0]->GetName(); if (oSetDimNames.find(osDimName) == oSetDimNames.end()) { oSetDimNames.insert(osDimName); @@ -1713,7 +1713,7 @@ netCDFVirtualGroupBySameDimension::GetMDArrayNames(CSLConstList) const auto poArray = m_poGroup->OpenMDArray(srcName, nullptr); if (poArray) { - const auto apoArrayDims = poArray->GetDimensions(); + const auto &apoArrayDims = poArray->GetDimensions(); if (apoArrayDims.size() == 1 && apoArrayDims[0]->GetName() == m_osDimName) { @@ -1932,7 +1932,7 @@ std::shared_ptr netCDFDimension::GetIndexingVariable() const if (!poArrayNC) continue; - const auto apoArrayDims = poArray->GetDimensions(); + const auto &apoArrayDims = poArray->GetDimensions(); if (apoArrayDims.size() == 1) { const auto &poArrayDim = apoArrayDims[0]; @@ -2598,7 +2598,7 @@ std::shared_ptr netCDFVariable::GetSpatialRef() const /* SetSpatialRef() */ /************************************************************************/ -static void WriteDimAttr(std::shared_ptr poVar, +static void WriteDimAttr(std::shared_ptr &poVar, const char *pszAttrName, const char *pszAttrValue) { auto poAttr = poVar->GetAttribute(pszAttrName); @@ -2622,7 +2622,7 @@ static void WriteDimAttr(std::shared_ptr poVar, } } -static void WriteDimAttrs(std::shared_ptr dim, +static void WriteDimAttrs(const std::shared_ptr &dim, const char *pszStandardName, const char *pszLongName, const char *pszUnits) { @@ -4739,7 +4739,7 @@ bool netCDFAttribute::IWrite(const GUInt64 *arrayStartIdx, const size_t *count, return true; } - const auto dt(GetDataType()); + const auto &dt(GetDataType()); if (dt.GetClass() == GEDTC_NUMERIC && dt.GetNumericDataType() == GDT_Unknown) { diff --git a/frmts/nitf/nitfdataset.cpp b/frmts/nitf/nitfdataset.cpp index 59642feb5dab..3c438f8737c9 100644 --- a/frmts/nitf/nitfdataset.cpp +++ b/frmts/nitf/nitfdataset.cpp @@ -1068,7 +1068,7 @@ NITFDataset *NITFDataset::OpenInternal(GDALOpenInfo *poOpenInfo, fabs(dfULY_AEQD - dfURY_AEQD) < 1e-6 * fabs(dfURY_AEQD) && fabs(dfLLY_AEQD - dfLRY_AEQD) < 1e-6 * fabs(dfLRY_AEQD)) { - poDS->m_oSRS = oSRS_AEQD; + poDS->m_oSRS = std::move(oSRS_AEQD); poDS->bGotGeoTransform = TRUE; poDS->adfGeoTransform[0] = dfULX_AEQD; @@ -2055,7 +2055,7 @@ void NITFDataset::CheckGeoSDEInfo() /* -------------------------------------------------------------------- */ /* Apply back to dataset. */ /* -------------------------------------------------------------------- */ - m_oSRS = oSRS; + m_oSRS = std::move(oSRS); memcpy(adfGeoTransform, adfGT, sizeof(double) * 6); bGotGeoTransform = TRUE; diff --git a/frmts/ogcapi/gdalogcapidataset.cpp b/frmts/ogcapi/gdalogcapidataset.cpp index 9cb83a6862f9..7071bc72d436 100644 --- a/frmts/ogcapi/gdalogcapidataset.cpp +++ b/frmts/ogcapi/gdalogcapidataset.cpp @@ -1597,25 +1597,22 @@ bool OGCAPIDataset::InitWithTilesAPI(GDALOpenInfo *poOpenInfo, } if (pszRequiredTileMatrixSet != nullptr) { - osTilesetURL = osCandidateTilesetURL; - break; + osTilesetURL = std::move(osCandidateTilesetURL); } - if (pszPreferredTileMatrixSet != nullptr && - !osCandidateTilesetURL.empty() && - (oTileMatrixSetURI.find(pszPreferredTileMatrixSet) != - std::string::npos)) + else if (pszPreferredTileMatrixSet != nullptr && + !osCandidateTilesetURL.empty() && + (oTileMatrixSetURI.find(pszPreferredTileMatrixSet) != + std::string::npos)) { - osTilesetURL = osCandidateTilesetURL; - break; + osTilesetURL = std::move(osCandidateTilesetURL); } - - if (oTileMatrixSetURI.find("WorldCRS84Quad") != std::string::npos) + else if (oTileMatrixSetURI.find("WorldCRS84Quad") != std::string::npos) { - osTilesetURL = osCandidateTilesetURL; + osTilesetURL = std::move(osCandidateTilesetURL); } else if (osTilesetURL.empty()) { - osTilesetURL = osCandidateTilesetURL; + osTilesetURL = std::move(osCandidateTilesetURL); } } if (osTilesetURL.empty()) diff --git a/frmts/pcidsk/sdk/channel/cexternalchannel.cpp b/frmts/pcidsk/sdk/channel/cexternalchannel.cpp index 89e69d9e9675..3b08eb7fe0b1 100644 --- a/frmts/pcidsk/sdk/channel/cexternalchannel.cpp +++ b/frmts/pcidsk/sdk/channel/cexternalchannel.cpp @@ -54,7 +54,7 @@ using namespace PCIDSK; CExternalChannel::CExternalChannel( PCIDSKBuffer &image_headerIn, uint64 ih_offsetIn, CPL_UNUSED PCIDSKBuffer &file_headerIn, - std::string filenameIn, + const std::string& filenameIn, int channelnumIn, CPCIDSKFile *fileIn, eChanType pixel_typeIn ) diff --git a/frmts/pcidsk/sdk/channel/cexternalchannel.h b/frmts/pcidsk/sdk/channel/cexternalchannel.h index 2eb898b5e255..a99b2d17a177 100644 --- a/frmts/pcidsk/sdk/channel/cexternalchannel.h +++ b/frmts/pcidsk/sdk/channel/cexternalchannel.h @@ -52,7 +52,7 @@ namespace PCIDSK CExternalChannel( PCIDSKBuffer &image_header, uint64 ih_offset, PCIDSKBuffer &file_header, - std::string filename, + const std::string& filename, int channelnum, CPCIDSKFile *file, eChanType pixel_type ); diff --git a/frmts/pcidsk/sdk/core/cpcidskfile.cpp b/frmts/pcidsk/sdk/core/cpcidskfile.cpp index ef51e9dfff63..cf299c97e27f 100644 --- a/frmts/pcidsk/sdk/core/cpcidskfile.cpp +++ b/frmts/pcidsk/sdk/core/cpcidskfile.cpp @@ -1109,7 +1109,7 @@ void CPCIDSKFile::FlushBlock() bool CPCIDSKFile::GetEDBFileDetails( EDBFile** file_p, Mutex **io_mutex_p, - std::string filename ) + const std::string& filename ) { *file_p = nullptr; @@ -1207,7 +1207,7 @@ std::string CPCIDSKFile::GetUniqueEDBFilename() //trigger call to AccessDB() poChannel->GetBlockWidth(); - std::string oFilename = poExt->GetExternalFilename(); + const std::string oFilename = poExt->GetExternalFilename(); if(oEDBName.size() == 0) { diff --git a/frmts/pcidsk/sdk/core/cpcidskfile.h b/frmts/pcidsk/sdk/core/cpcidskfile.h index 5ff0c6c3895d..c3ead995b01d 100644 --- a/frmts/pcidsk/sdk/core/cpcidskfile.h +++ b/frmts/pcidsk/sdk/core/cpcidskfile.h @@ -49,8 +49,8 @@ namespace PCIDSK /************************************************************************/ class CPCIDSKFile final: public PCIDSKFile { - friend PCIDSKFile PCIDSK_DLL *Open( std::string filename, - std::string access, const PCIDSKInterfaces *interfaces, int max_channel_count_allowed ); + friend PCIDSKFile PCIDSK_DLL *Open( const std::string& filename, + const std::string& access, const PCIDSKInterfaces *interfaces, int max_channel_count_allowed ); public: CPCIDSKFile( const std::string& filename ); @@ -97,7 +97,7 @@ namespace PCIDSK const std::string& filename=std::string(), bool writable=false ) override; bool GetEDBFileDetails( EDBFile** file_p, Mutex **io_mutex_p, - std::string filename ); + const std::string& filename ); std::string GetUniqueEDBFilename() override; diff --git a/frmts/pcidsk/sdk/core/pcidsk_utils.cpp b/frmts/pcidsk/sdk/core/pcidsk_utils.cpp index a3f8f201ac86..9c607c370651 100644 --- a/frmts/pcidsk/sdk/core/pcidsk_utils.cpp +++ b/frmts/pcidsk/sdk/core/pcidsk_utils.cpp @@ -321,12 +321,13 @@ bool PCIDSK::BigEndianSystem() /* _DBLayout metadata. */ /************************************************************************/ -void PCIDSK::ParseTileFormat(std::string oOptions, +void PCIDSK::ParseTileFormat(const std::string& oOptionsIn, int & nTileSize, std::string & oCompress) { nTileSize = PCIDSK_DEFAULT_TILE_SIZE; oCompress = "NONE"; + std::string oOptions(oOptionsIn); UCaseStr(oOptions); std::string::size_type nStart = oOptions.find_first_not_of(" "); @@ -334,7 +335,7 @@ void PCIDSK::ParseTileFormat(std::string oOptions, while (nStart != std::string::npos || nEnd != std::string::npos) { - std::string oToken = oOptions.substr(nStart, nEnd - nStart); + const std::string oToken = oOptions.substr(nStart, nEnd - nStart); if (oToken.size() > 5 && STARTS_WITH(oToken.c_str(), "TILED")) { diff --git a/frmts/pcidsk/sdk/core/pcidsk_utils.h b/frmts/pcidsk/sdk/core/pcidsk_utils.h index 1af255ab3b50..d4dc34244edc 100644 --- a/frmts/pcidsk/sdk/core/pcidsk_utils.h +++ b/frmts/pcidsk/sdk/core/pcidsk_utils.h @@ -59,7 +59,7 @@ namespace PCIDSK bool BigEndianSystem(void); void GetCurrentDateTime( char *out_datetime ); - void ParseTileFormat(std::string oOptions, int & nTileSize, + void ParseTileFormat(const std::string& oOptions, int & nTileSize, std::string & oCompress); void SwapPixels(void* const data, diff --git a/frmts/pcidsk/sdk/core/pcidskcreate.cpp b/frmts/pcidsk/sdk/core/pcidskcreate.cpp index d20de968b204..90b5fc3d7079 100644 --- a/frmts/pcidsk/sdk/core/pcidskcreate.cpp +++ b/frmts/pcidsk/sdk/core/pcidskcreate.cpp @@ -65,9 +65,9 @@ using namespace PCIDSK; */ PCIDSKFile PCIDSK_DLL * -PCIDSK::Create( std::string filename, int pixels, int lines, +PCIDSK::Create( const std::string& filename, int pixels, int lines, int channel_count, eChanType *channel_types, - std::string options, const PCIDSKInterfaces *interfaces ) + const std::string& oOrigOptions, const PCIDSKInterfaces *interfaces ) { if( pixels < 0 || pixels > 99999999 || @@ -105,7 +105,7 @@ PCIDSK::Create( std::string filename, int pixels, int lines, int tilesize = PCIDSK_DEFAULT_TILE_SIZE; std::string oLinkFilename; - const std::string oOrigOptions = options; + std::string options = oOrigOptions; UCaseStr( options ); for(auto & c : options) { diff --git a/frmts/pcidsk/sdk/core/pcidskopen.cpp b/frmts/pcidsk/sdk/core/pcidskopen.cpp index 911e97f65f90..c2e4b70d167f 100644 --- a/frmts/pcidsk/sdk/core/pcidskopen.cpp +++ b/frmts/pcidsk/sdk/core/pcidskopen.cpp @@ -54,7 +54,7 @@ using namespace PCIDSK; * @return a pointer to a file object for accessing the PCIDSK file. */ -PCIDSKFile *PCIDSK::Open( std::string filename, std::string access, +PCIDSKFile *PCIDSK::Open( const std::string& filename, const std::string& access, const PCIDSKInterfaces *interfaces, int max_channel_count ) diff --git a/frmts/pcidsk/sdk/pcidsk.h b/frmts/pcidsk/sdk/pcidsk.h index 837bcf1d5175..262b7ee978d2 100644 --- a/frmts/pcidsk/sdk/pcidsk.h +++ b/frmts/pcidsk/sdk/pcidsk.h @@ -53,13 +53,13 @@ namespace PCIDSK { /************************************************************************/ /* PCIDSK Access Functions */ /************************************************************************/ -PCIDSKFile PCIDSK_DLL *Open( std::string filename, std::string access, +PCIDSKFile PCIDSK_DLL *Open( const std::string& filename, const std::string& access, const PCIDSKInterfaces *interfaces = nullptr, int max_channel_count_allowed = -1 ); -PCIDSKFile PCIDSK_DLL *Create( std::string filename, int pixels, int lines, +PCIDSKFile PCIDSK_DLL *Create( const std::string& filename, int pixels, int lines, int channel_count, eChanType *channel_types, - std::string options, + const std::string& options, const PCIDSKInterfaces *interfaces = nullptr ); diff --git a/frmts/pcidsk/sdk/pcidsk_io.h b/frmts/pcidsk/sdk/pcidsk_io.h index 805e5de88130..0e017d200daa 100644 --- a/frmts/pcidsk/sdk/pcidsk_io.h +++ b/frmts/pcidsk/sdk/pcidsk_io.h @@ -44,7 +44,7 @@ namespace PCIDSK { public: virtual ~IOInterfaces() {} - virtual void *Open( std::string filename, std::string access ) const = 0; + virtual void *Open( const std::string& filename, std::string access ) const = 0; virtual uint64 Seek( void *io_handle, uint64 offset, int whence ) const = 0; virtual uint64 Tell( void *io_handle ) const = 0; virtual uint64 Read( void *buffer, uint64 size, uint64 nmemb, void *io_handle ) const = 0; diff --git a/frmts/pcidsk/vsi_pcidsk_io.cpp b/frmts/pcidsk/vsi_pcidsk_io.cpp index 02a8bbf8a496..89ebfccddff3 100644 --- a/frmts/pcidsk/vsi_pcidsk_io.cpp +++ b/frmts/pcidsk/vsi_pcidsk_io.cpp @@ -42,7 +42,8 @@ const PCIDSK::PCIDSKInterfaces *PCIDSK2GetInterfaces(); class VSI_IOInterface : public IOInterfaces { - virtual void *Open(std::string filename, std::string access) const override; + virtual void *Open(const std::string &filename, + std::string access) const override; virtual uint64 Seek(void *io_handle, uint64 offset, int whence) const override; virtual uint64 Tell(void *io_handle) const override; @@ -76,7 +77,8 @@ const PCIDSK::PCIDSKInterfaces *PCIDSK2GetInterfaces() /* Open() */ /************************************************************************/ -void *VSI_IOInterface::Open(std::string filename, std::string access) const +void *VSI_IOInterface::Open(const std::string &filename, + std::string access) const { VSILFILE *fp = VSIFOpenL(filename.c_str(), access.c_str()); diff --git a/frmts/pdf/pdfdataset.cpp b/frmts/pdf/pdfdataset.cpp index c94d523cd010..f15ba43145d1 100644 --- a/frmts/pdf/pdfdataset.cpp +++ b/frmts/pdf/pdfdataset.cpp @@ -3935,9 +3935,13 @@ void PDFDataset::ExploreLayersPdfium(GDALPDFArray *poArray, int nRecLevel, PDFSanitizeLayerName(poName->GetString().c_str()); // coverity[copy_paste_error] if (!osTopLayer.empty()) - osCurLayer = osTopLayer + "." + osName; + { + osCurLayer = osTopLayer; + osCurLayer += '.'; + osCurLayer += std::move(osName); + } else - osCurLayer = osName; + osCurLayer = std::move(osName); // CPLDebug("PDF", "Layer %s", osCurLayer.c_str()); AddLayer(osCurLayer.c_str()); @@ -6474,7 +6478,7 @@ int PDFDataset::ParseProjDict(GDALPDFDictionary *poProjDict) /* -------------------------------------------------------------------- */ /* Export SpatialRef */ /* -------------------------------------------------------------------- */ - m_oSRS = oSRS; + m_oSRS = std::move(oSRS); return TRUE; } @@ -6863,7 +6867,7 @@ int PDFDataset::ParseMeasure(GDALPDFObject *poMeasure, double dfMediaBoxWidth, } if (bSRSOK) { - m_oSRS = oSRS_ESRI; + m_oSRS = std::move(oSRS_ESRI); } } } diff --git a/frmts/pdf/pdfobject.cpp b/frmts/pdf/pdfobject.cpp index 7817a67bb528..0ef15367c7f3 100644 --- a/frmts/pdf/pdfobject.cpp +++ b/frmts/pdf/pdfobject.cpp @@ -2320,7 +2320,7 @@ GDALPDFObjectPdfium::Build(RetainPtr obj) return nullptr; } } - return new GDALPDFObjectPdfium(obj); + return new GDALPDFObjectPdfium(std::move(obj)); } /************************************************************************/ diff --git a/frmts/pds/isis2dataset.cpp b/frmts/pds/isis2dataset.cpp index 06bf83002bee..588c29353e47 100644 --- a/frmts/pds/isis2dataset.cpp +++ b/frmts/pds/isis2dataset.cpp @@ -426,7 +426,7 @@ GDALDataset *ISIS2Dataset::Open(GDALOpenInfo *poOpenInfo) /*********** Grab TARGET_NAME ************/ /**** This is the planets name i.e. MARS ***/ - CPLString target_name = poDS->GetKeyword("QUBE.TARGET_NAME"); + const CPLString target_name = poDS->GetKeyword("QUBE.TARGET_NAME"); /*********** Grab MAP_PROJECTION_TYPE ************/ CPLString map_proj_name = @@ -620,7 +620,7 @@ GDALDataset *ISIS2Dataset::Open(GDALOpenInfo *poOpenInfo) } // translate back into a projection string. - poDS->m_oSRS = oSRS; + poDS->m_oSRS = std::move(oSRS); } /* END ISIS2 Label Read */ diff --git a/frmts/pds/isis3dataset.cpp b/frmts/pds/isis3dataset.cpp index fa6d07621221..957cf9ddb293 100644 --- a/frmts/pds/isis3dataset.cpp +++ b/frmts/pds/isis3dataset.cpp @@ -1693,14 +1693,13 @@ GDALDataset *ISIS3Dataset::Open(GDALOpenInfo *poOpenInfo) /* What file contains the actual data? */ /* -------------------------------------------------------------------- */ const char *pszCore = poDS->GetKeyword("IsisCube.Core.^Core"); - CPLString osQubeFile; - - if (EQUAL(pszCore, "")) - osQubeFile = poOpenInfo->pszFilename; - else + const CPLString osQubeFile( + EQUAL(pszCore, "") + ? poOpenInfo->pszFilename + : CPLFormFilename(CPLGetPath(poOpenInfo->pszFilename), pszCore, + nullptr)); + if (!EQUAL(pszCore, "")) { - CPLString osPath = CPLGetPath(poOpenInfo->pszFilename); - osQubeFile = CPLFormFilename(osPath, pszCore, nullptr); poDS->m_osExternalFilename = osQubeFile; } @@ -2064,7 +2063,7 @@ GDALDataset *ISIS3Dataset::Open(GDALOpenInfo *poOpenInfo) } // translate back into a projection string. - poDS->m_oSRS = oSRS; + poDS->m_oSRS = std::move(oSRS); poDS->m_oSRS.SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER); } @@ -3188,7 +3187,7 @@ void ISIS3Dataset::BuildLabel() m_aoNonPixelSections.push_back(oSection); } } - m_oJSonLabel = oLabel; + m_oJSonLabel = std::move(oLabel); } /************************************************************************/ @@ -3345,7 +3344,7 @@ void ISIS3Dataset::BuildHistory() osHistory += SerializeAsPDL(oHistoryObj); } - m_osHistory = osHistory; + m_osHistory = std::move(osHistory); } /************************************************************************/ diff --git a/frmts/pds/pdsdataset.cpp b/frmts/pds/pdsdataset.cpp index 8553784517c1..0502d65e117e 100644 --- a/frmts/pds/pdsdataset.cpp +++ b/frmts/pds/pdsdataset.cpp @@ -86,7 +86,7 @@ class PDSDataset final : public RawDataset int ParseCompressedImage(); int ParseImage(const CPLString &osPrefix, const CPLString &osFilenamePrefix); - static void CleanString(CPLString &osInput); + static CPLString CleanString(const CPLString &osInput); const char *GetKeyword(const std::string &osPath, const char *pszDefault = ""); @@ -416,13 +416,11 @@ void PDSDataset::ParseSRS() /*********** Grab TARGET_NAME ************/ /**** This is the planets name i.e. MARS ***/ - CPLString target_name = GetKeyword("TARGET_NAME"); - CleanString(target_name); + const CPLString target_name = CleanString(GetKeyword("TARGET_NAME")); /********** Grab MAP_PROJECTION_TYPE *****/ - CPLString map_proj_name = - GetKeyword(osPrefix + "IMAGE_MAP_PROJECTION.MAP_PROJECTION_TYPE"); - CleanString(map_proj_name); + const CPLString map_proj_name = CleanString( + GetKeyword(osPrefix + "IMAGE_MAP_PROJECTION.MAP_PROJECTION_TYPE")); /****** Grab semi_major & convert to KM ******/ const double semi_major = @@ -689,7 +687,7 @@ void PDSDataset::ParseSRS() } // translate back into a projection string. - m_oSRS = oSRS; + m_oSRS = std::move(oSRS); } /* ==================================================================== */ @@ -856,8 +854,7 @@ int PDSDataset::ParseImage(const CPLString &osPrefix, if (!osQube.empty() && osQube[0] == '"') { - CPLString osFilename = osQube; - CleanString(osFilename); + const CPLString osFilename = CleanString(osQube); if (!osFilenamePrefix.empty()) { m_osImageFilename = osFilenamePrefix + osFilename; @@ -877,9 +874,8 @@ int PDSDataset::ParseImage(const CPLString &osPrefix, /* Compressed types will not be supported in this routine */ /* -------------------------------------------------------------------- */ - CPLString osEncodingType = - GetKeyword(osPrefix + "IMAGE.ENCODING_TYPE", "N/A"); - CleanString(osEncodingType); + const CPLString osEncodingType = + CleanString(GetKeyword(osPrefix + "IMAGE.ENCODING_TYPE", "N/A")); if (!EQUAL(osEncodingType, "N/A") && !EQUAL(osEncodingType, "DCT_DECOMPRESSED")) { @@ -1345,8 +1341,8 @@ class PDSWrapperRasterBand final : public GDALProxyRasterBand int PDSDataset::ParseCompressedImage() { - CPLString osFileName = GetKeyword("COMPRESSED_FILE.FILE_NAME", ""); - CleanString(osFileName); + const CPLString osFileName = + CleanString(GetKeyword("COMPRESSED_FILE.FILE_NAME", "")); const CPLString osPath = CPLGetPath(GetDescription()); const CPLString osFullFileName = @@ -1428,15 +1424,14 @@ GDALDataset *PDSDataset::Open(GDALOpenInfo *poOpenInfo) poDS->GetKeyword("COMPRESSED_FILE.ENCODING_TYPE", ""); CPLString osCompressedFilename = - poDS->GetKeyword("COMPRESSED_FILE.FILE_NAME", ""); - CleanString(osCompressedFilename); + CleanString(poDS->GetKeyword("COMPRESSED_FILE.FILE_NAME", "")); - CPLString osUncompressedFilename = + const char *pszImageName = poDS->GetKeyword("UNCOMPRESSED_FILE.IMAGE.NAME", ""); - if (osUncompressedFilename.empty()) - osUncompressedFilename = - poDS->GetKeyword("UNCOMPRESSED_FILE.FILE_NAME", ""); - CleanString(osUncompressedFilename); + CPLString osUncompressedFilename = + CleanString(!EQUAL(pszImageName, "") + ? pszImageName + : poDS->GetKeyword("UNCOMPRESSED_FILE.FILE_NAME", "")); VSIStatBufL sStat; CPLString osFilenamePrefix; @@ -1607,16 +1602,15 @@ const char *PDSDataset::GetKeywordUnit(const char *pszPath, int iSubscript, /* CleanString() */ /* */ /* Removes single or double quotes, and converts spaces to underscores. */ -/* The change is made in-place to CPLString. */ /************************************************************************/ -void PDSDataset::CleanString(CPLString &osInput) +CPLString PDSDataset::CleanString(const CPLString &osInput) { if ((osInput.size() < 2) || ((osInput.at(0) != '"' || osInput.back() != '"') && (osInput.at(0) != '\'' || osInput.back() != '\''))) - return; + return osInput; char *pszWrk = CPLStrdup(osInput.c_str() + 1); @@ -1628,8 +1622,9 @@ void PDSDataset::CleanString(CPLString &osInput) pszWrk[i] = '_'; } - osInput = pszWrk; + CPLString osOutput = pszWrk; CPLFree(pszWrk); + return osOutput; } /************************************************************************/ diff --git a/frmts/pds/vicardataset.cpp b/frmts/pds/vicardataset.cpp index 634866123135..4a123e10840a 100644 --- a/frmts/pds/vicardataset.cpp +++ b/frmts/pds/vicardataset.cpp @@ -1750,7 +1750,7 @@ void VICARDataset::BuildLabel() } } - m_oJSonLabel = oLabel; + m_oJSonLabel = std::move(oLabel); } /************************************************************************/ @@ -2278,7 +2278,7 @@ void VICARDataset::ReadProjectionFromMapGroup() } } - m_oSRS = oSRS; + m_oSRS = std::move(oSRS); m_oSRS.SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER); } if (bProjectionSet) diff --git a/frmts/plmosaic/plmosaicdataset.cpp b/frmts/plmosaic/plmosaicdataset.cpp index 9aab69ca50b3..f29ef599c140 100644 --- a/frmts/plmosaic/plmosaicdataset.cpp +++ b/frmts/plmosaic/plmosaicdataset.cpp @@ -108,9 +108,9 @@ class PLMosaicDataset final : public GDALPamDataset std::vector ListSubdatasets(); static CPLString formatTileName(int tile_x, int tile_y); - void InsertNewDataset(CPLString osKey, GDALDataset *poDS); - GDALDataset *OpenAndInsertNewDataset(CPLString osTmpFilename, - CPLString osTilename); + void InsertNewDataset(const CPLString &osKey, GDALDataset *poDS); + GDALDataset *OpenAndInsertNewDataset(const CPLString &osTmpFilename, + const CPLString &osTilename); public: PLMosaicDataset(); @@ -1196,7 +1196,8 @@ CPLString PLMosaicDataset::formatTileName(int tile_x, int tile_y) /* InsertNewDataset() */ /************************************************************************/ -void PLMosaicDataset::InsertNewDataset(CPLString osKey, GDALDataset *poDS) +void PLMosaicDataset::InsertNewDataset(const CPLString &osKey, + GDALDataset *poDS) { if (static_cast(oMapLinkedDatasets.size()) == nCacheMaxSize) { @@ -1227,8 +1228,9 @@ void PLMosaicDataset::InsertNewDataset(CPLString osKey, GDALDataset *poDS) /* OpenAndInsertNewDataset() */ /************************************************************************/ -GDALDataset *PLMosaicDataset::OpenAndInsertNewDataset(CPLString osTmpFilename, - CPLString osTilename) +GDALDataset * +PLMosaicDataset::OpenAndInsertNewDataset(const CPLString &osTmpFilename, + const CPLString &osTilename) { const char *const apszAllowedDrivers[2] = {"GTiff", nullptr}; GDALDataset *poDS = GDALDataset::FromHandle( diff --git a/frmts/prf/phprfdataset.cpp b/frmts/prf/phprfdataset.cpp index ab47bf270607..836d26cb5a38 100644 --- a/frmts/prf/phprfdataset.cpp +++ b/frmts/prf/phprfdataset.cpp @@ -320,15 +320,15 @@ static GDALDataType ParseChannelsInfo(const CPLXMLNode *psElt) if (EQUAL(osName, "type")) { - osType = osValue; + osType = std::move(osValue); } else if (EQUAL(osName, "bytes_ps")) { - osBytesPS = osValue; + osBytesPS = std::move(osValue); } else if (EQUAL(osName, "channels")) { - osChannels = osValue; + osChannels = std::move(osValue); } } diff --git a/frmts/raw/byndataset.cpp b/frmts/raw/byndataset.cpp index 8bd609050a1c..811920a08731 100644 --- a/frmts/raw/byndataset.cpp +++ b/frmts/raw/byndataset.cpp @@ -496,7 +496,7 @@ const OGRSpatialReference *BYNDataset::GetSpatialRef() const { /* Return COMPD_CS with GEOGCS and VERT_CS */ - m_oSRS = oSRSComp; + m_oSRS = std::move(oSRSComp); m_oSRS.SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER); return &m_oSRS; } diff --git a/frmts/raw/dipxdataset.cpp b/frmts/raw/dipxdataset.cpp index 025a3e9f26c5..05936fd14553 100644 --- a/frmts/raw/dipxdataset.cpp +++ b/frmts/raw/dipxdataset.cpp @@ -296,7 +296,7 @@ GDALDataset *DIPExDataset::Open(GDALOpenInfo *poOpenInfo) oSR.SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER); if (oSR.importFromEPSG(poDS->sHeader.SRID) == OGRERR_NONE) { - poDS->m_oSRS = oSR; + poDS->m_oSRS = std::move(oSR); } } diff --git a/frmts/raw/eirdataset.cpp b/frmts/raw/eirdataset.cpp index c75835b70741..a6dbbb325a1f 100644 --- a/frmts/raw/eirdataset.cpp +++ b/frmts/raw/eirdataset.cpp @@ -448,7 +448,7 @@ GDALDataset *EIRDataset::Open(GDALOpenInfo *poOpenInfo) /* -------------------------------------------------------------------- */ poDS->nRasterXSize = nCols; poDS->nRasterYSize = nRows; - poDS->aosHDR = aosHDR; + poDS->aosHDR = std::move(aosHDR); /* -------------------------------------------------------------------- */ /* Open target binary file. */ diff --git a/frmts/raw/hkvdataset.cpp b/frmts/raw/hkvdataset.cpp index 1048ec9feaee..01e857d5d718 100644 --- a/frmts/raw/hkvdataset.cpp +++ b/frmts/raw/hkvdataset.cpp @@ -1183,7 +1183,7 @@ void HKVDataset::ProcessGeoref(const char *pszFilename) } else { - m_oSRS = oUTM; + m_oSRS = std::move(oUTM); } } @@ -1244,7 +1244,7 @@ void HKVDataset::ProcessGeoref(const char *pszFilename) m_oSRS = oLL; } - m_oGCPSRS = oLL; + m_oGCPSRS = std::move(oLL); } delete hkvEllipsoids; diff --git a/frmts/raw/mffdataset.cpp b/frmts/raw/mffdataset.cpp index bda08409798c..1d5db2a75cb2 100644 --- a/frmts/raw/mffdataset.cpp +++ b/frmts/raw/mffdataset.cpp @@ -648,7 +648,7 @@ void MFFDataset::ScanForProjectionInfo() } m_oSRS = oProj; - m_oGCPSRS = oProj; + m_oGCPSRS = std::move(oProj); if (!transform_ok) { diff --git a/frmts/raw/ndfdataset.cpp b/frmts/raw/ndfdataset.cpp index b53abcb108da..d6d91d670030 100644 --- a/frmts/raw/ndfdataset.cpp +++ b/frmts/raw/ndfdataset.cpp @@ -383,7 +383,7 @@ GDALDataset *NDFDataset::Open(GDALOpenInfo *poOpenInfo) if (oSRS.GetRoot() != nullptr) { - poDS->m_oSRS = oSRS; + poDS->m_oSRS = std::move(oSRS); } /* -------------------------------------------------------------------- */ diff --git a/frmts/raw/roipacdataset.cpp b/frmts/raw/roipacdataset.cpp index 06ba312abe00..316a9873a4bb 100644 --- a/frmts/raw/roipacdataset.cpp +++ b/frmts/raw/roipacdataset.cpp @@ -447,7 +447,7 @@ GDALDataset *ROIPACDataset::Open(GDALOpenInfo *poOpenInfo) oSRS.SetWellKnownGeogCS("NAD27"); } } - poDS->m_oSRS = oSRS; + poDS->m_oSRS = std::move(oSRS); poDS->m_oSRS.SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER); } if (aosRSC.FetchNameValue("Z_OFFSET") != nullptr) diff --git a/frmts/raw/rrasterdataset.cpp b/frmts/raw/rrasterdataset.cpp index f4aef1c7f81a..db93d6e7da35 100644 --- a/frmts/raw/rrasterdataset.cpp +++ b/frmts/raw/rrasterdataset.cpp @@ -1452,11 +1452,13 @@ GDALDataset *RRASTERDataset::Create(const char *pszFilename, int nXSize, return nullptr; } - CPLString osGRIExtension((osGRDExtension[0] == 'g') ? "gri" : "GRI"); - CPLString osGriFilename(CPLResetExtension(pszFilename, osGRIExtension)); + const std::string osGRIExtension((osGRDExtension[0] == 'g') ? "gri" + : "GRI"); + const std::string osGriFilename( + CPLResetExtension(pszFilename, osGRIExtension.c_str())); // Try to create the file. - VSILFILE *fpImage = VSIFOpenL(osGriFilename, "wb+"); + VSILFILE *fpImage = VSIFOpenL(osGriFilename.c_str(), "wb+"); if (fpImage == nullptr) { diff --git a/frmts/raw/snodasdataset.cpp b/frmts/raw/snodasdataset.cpp index 4df5e4e858c8..b460922236ce 100644 --- a/frmts/raw/snodasdataset.cpp +++ b/frmts/raw/snodasdataset.cpp @@ -460,7 +460,7 @@ GDALDataset *SNODASDataset::Open(GDALOpenInfo *poOpenInfo) poDS->nRasterXSize = nCols; poDS->nRasterYSize = nRows; - poDS->osDataFilename = osDataFilename; + poDS->osDataFilename = std::move(osDataFilename); poDS->bHasNoData = bHasNoData; poDS->dfNoData = dfNoData; poDS->bHasMin = bHasMin; diff --git a/frmts/rs2/rs2dataset.cpp b/frmts/rs2/rs2dataset.cpp index 1c04692d9640..fcf4f43737ca 100644 --- a/frmts/rs2/rs2dataset.cpp +++ b/frmts/rs2/rs2dataset.cpp @@ -1292,7 +1292,7 @@ GDALDataset *RS2Dataset::Open(GDALOpenInfo *poOpenInfo) if (bUseProjInfo) { - poDS->m_oSRS = oPrj; + poDS->m_oSRS = std::move(oPrj); } else { @@ -1303,7 +1303,7 @@ GDALDataset *RS2Dataset::Open(GDALOpenInfo *poOpenInfo) } } - poDS->m_oGCPSRS = oLL; + poDS->m_oGCPSRS = std::move(oLL); } /* -------------------------------------------------------------------- */ diff --git a/frmts/safe/safedataset.cpp b/frmts/safe/safedataset.cpp index 1476dc8d0d96..ff557737c93c 100644 --- a/frmts/safe/safedataset.cpp +++ b/frmts/safe/safedataset.cpp @@ -1377,7 +1377,7 @@ GDALDataset *SAFEDataset::Open(GDALOpenInfo *poOpenInfo) } oLL.SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER); - poDS->m_oGCPSRS = oLL; + poDS->m_oGCPSRS = std::move(oLL); } /* -------------------------------------------------------------------- diff --git a/frmts/sigdem/sigdemdataset.cpp b/frmts/sigdem/sigdemdataset.cpp index 2c592b3fa7d5..89edc213fb64 100644 --- a/frmts/sigdem/sigdemdataset.cpp +++ b/frmts/sigdem/sigdemdataset.cpp @@ -412,7 +412,7 @@ GDALDataset *SIGDEMDataset::Open(GDALOpenInfo *poOpenInfo) } SIGDEMDataset *poDS = new SIGDEMDataset(sHeader); - poDS->m_oSRS = oSRS; + poDS->m_oSRS = std::move(oSRS); poDS->fpImage = poOpenInfo->fpL; poOpenInfo->fpL = nullptr; diff --git a/frmts/stacit/stacitdataset.cpp b/frmts/stacit/stacitdataset.cpp index 5ebe50b4c35a..0374928d0161 100644 --- a/frmts/stacit/stacitdataset.cpp +++ b/frmts/stacit/stacitdataset.cpp @@ -363,7 +363,7 @@ static void ParseAsset(const CPLJSONObject &jAsset, { Collection collection; collection.osName = osCollection; - oMapCollection[osCollection] = collection; + oMapCollection[osCollection] = std::move(collection); } auto &collection = oMapCollection[osCollection]; diff --git a/frmts/stacta/stactadataset.cpp b/frmts/stacta/stactadataset.cpp index 2f76774baeb1..675040acf940 100644 --- a/frmts/stacta/stactadataset.cpp +++ b/frmts/stacta/stactadataset.cpp @@ -888,7 +888,7 @@ bool STACTADataset::Open(GDALOpenInfo *poOpenInfo) } } } - const auto tmsList = poTMS->tileMatrixList(); + const auto &tmsList = poTMS->tileMatrixList(); if (tmsList.empty()) return false; diff --git a/frmts/tiledb/tiledbmultidimgroup.cpp b/frmts/tiledb/tiledbmultidimgroup.cpp index 55f5fee660ea..7a396801a139 100644 --- a/frmts/tiledb/tiledbmultidimgroup.cpp +++ b/frmts/tiledb/tiledbmultidimgroup.cpp @@ -247,7 +247,7 @@ TileDBGroup::OpenGroup(const std::string &osName, } } if (osSubPath.empty()) - osSubPath = osSubPathCandidate; + osSubPath = std::move(osSubPathCandidate); if (osSubPath.empty()) return nullptr; diff --git a/frmts/tsx/tsxdataset.cpp b/frmts/tsx/tsxdataset.cpp index 0c1509fc0839..57b4f2aa74a2 100644 --- a/frmts/tsx/tsxdataset.cpp +++ b/frmts/tsx/tsxdataset.cpp @@ -439,7 +439,7 @@ bool TSXDataset::getGCPsFromGEOREF_XML(char *pszGeorefFilename) // CPLAtof(CPLGetXMLValue(psNode,"height","")); } - m_oGCPSRS = osr; + m_oGCPSRS = std::move(osr); CPLDestroyXMLNode(psGeorefData); diff --git a/frmts/usgsdem/usgsdemdataset.cpp b/frmts/usgsdem/usgsdemdataset.cpp index 682307a7e20d..6e9db6b27b2c 100644 --- a/frmts/usgsdem/usgsdemdataset.cpp +++ b/frmts/usgsdem/usgsdemdataset.cpp @@ -793,7 +793,7 @@ int USGSDEMDataset::LoadFromFile(VSILFILE *InDem) sr.SetStatePlane(iUTMZone, bNAD83); } - m_oSRS = sr; + m_oSRS = std::move(sr); /* -------------------------------------------------------------------- */ /* For UTM we use the extents (really the UTM coordinates of */ diff --git a/frmts/vrt/vrtmultidim.cpp b/frmts/vrt/vrtmultidim.cpp index 2ecf9045a7a3..d4305915a126 100644 --- a/frmts/vrt/vrtmultidim.cpp +++ b/frmts/vrt/vrtmultidim.cpp @@ -1455,7 +1455,7 @@ bool VRTMDArraySourceInlinedValues::Read( std::vector abyStackDstPtr(nDims + 1); abyStackDstPtr[0] = static_cast(pDstBuffer) + nDstOffset; - const auto dt(m_poDstArray->GetDataType()); + const auto &dt(m_poDstArray->GetDataType()); std::vector anStackCount(nDims); size_t iDim = 0; @@ -1498,7 +1498,7 @@ bool VRTMDArraySourceInlinedValues::Read( void VRTMDArraySourceInlinedValues::Serialize(CPLXMLNode *psParent, const char *) const { - const auto dt(m_poDstArray->GetDataType()); + const auto &dt(m_poDstArray->GetDataType()); CPLXMLNode *psSource = CPLCreateXMLNode(psParent, CXT_Element, m_bIsConstantValue ? "ConstantValue" : dt.GetClass() == GEDTC_STRING @@ -2714,8 +2714,7 @@ CPLErr VRTArraySource::XMLInit( { return CE_Failure; } - auto apoDims = poArray->GetDimensions(); - if (apoDims.size() != 2) + if (poArray->GetDimensionCount() != 2) { CPLError(CE_Failure, CPLE_NotSupported, "Array referenced in should be a " diff --git a/frmts/wcs/wcsdataset100.cpp b/frmts/wcs/wcsdataset100.cpp index 3e927e8c821a..bab8df830b09 100644 --- a/frmts/wcs/wcsdataset100.cpp +++ b/frmts/wcs/wcsdataset100.cpp @@ -581,46 +581,32 @@ CPLErr WCSDataset100::ParseCapabilities(CPLXMLNode *Capabilities, // identification metadata CPLString path2 = path; - std::vector keys2; - keys2.push_back("description"); - keys2.push_back("name"); - keys2.push_back("label"); - keys2.push_back("fees"); - keys2.push_back("accessConstraints"); - CPLXMLNode *service = - AddSimpleMetaData(&metadata, Capabilities, path2, "Service", keys2); + CPLXMLNode *service = AddSimpleMetaData( + &metadata, Capabilities, path2, "Service", + {"description", "name", "label", "fees", "accessConstraints"}); if (service) { - CPLString path3 = path2; - std::vector keys3; - keys3.push_back("individualName"); - keys3.push_back("organisationName"); - keys3.push_back("positionName"); + CPLString path3 = std::move(path2); CPLString kw = GetKeywords(service, "keywords", "keyword"); if (kw != "") { CPLString name = path + "keywords"; metadata = CSLSetNameValue(metadata, name, kw); } - CPLXMLNode *party = AddSimpleMetaData(&metadata, service, path3, - "responsibleParty", keys3); + CPLXMLNode *party = AddSimpleMetaData( + &metadata, service, path3, "responsibleParty", + {"individualName", "organisationName", "positionName"}); CPLXMLNode *info = CPLGetXMLNode(party, "contactInfo"); if (party && info) { CPLString path4 = path3 + "contactInfo."; - std::vector keys4; - keys4.push_back("deliveryPoint"); - keys4.push_back("city"); - keys4.push_back("administrativeArea"); - keys4.push_back("postalCode"); - keys4.push_back("country"); - keys4.push_back("electronicMailAddress"); CPLString path5 = path4; - std::vector keys5; - keys5.push_back("voice"); - keys5.push_back("facsimile"); - AddSimpleMetaData(&metadata, info, path4, "address", keys4); - AddSimpleMetaData(&metadata, info, path5, "phone", keys5); + AddSimpleMetaData(&metadata, info, path4, "address", + {"deliveryPoint", "city", "administrativeArea", + "postalCode", "country", + "electronicMailAddress"}); + AddSimpleMetaData(&metadata, info, path5, "phone", + {"voice", "facsimile"}); } } diff --git a/frmts/wcs/wcsdataset110.cpp b/frmts/wcs/wcsdataset110.cpp index 9b9f916c4909..2a6b48215888 100644 --- a/frmts/wcs/wcsdataset110.cpp +++ b/frmts/wcs/wcsdataset110.cpp @@ -766,6 +766,7 @@ CPLErr WCSDataset110::ParseCapabilities(CPLXMLNode *Capabilities, "Country", "ElectronicMailAddress"}); AddSimpleMetaData(&metadata, info, path6, "Phone", {"Voice", "Facsimile"}); + CPL_IGNORE_RET_VAL(path4); } } } diff --git a/frmts/wms/minidriver_tiled_wms.cpp b/frmts/wms/minidriver_tiled_wms.cpp index 50972a863043..48bdc10139ae 100644 --- a/frmts/wms/minidriver_tiled_wms.cpp +++ b/frmts/wms/minidriver_tiled_wms.cpp @@ -412,7 +412,7 @@ CPLErr WMSMiniDriver_TiledWMS::Initialize(CPLXMLNode *config, for (int i = 0, n = CSLCount(substs); i < n && substs; i++) m_parent_dataset->SetMetadataItem("Change", substs[i], nullptr); - CPLString GTS(CPLGetXMLValue(config, "Configuration", "")); + const CPLString GTS(CPLGetXMLValue(config, "Configuration", "")); CPLString decodedGTS; if (GTS.size() != 0) diff --git a/frmts/wms/wmsdriver.cpp b/frmts/wms/wmsdriver.cpp index 6d3fbf58499a..6dd0f93965dc 100644 --- a/frmts/wms/wmsdriver.cpp +++ b/frmts/wms/wmsdriver.cpp @@ -68,18 +68,20 @@ static CPLXMLNode *GDALWMSDatasetGetConfigFromURL(GDALOpenInfo *poOpenInfo) if (STARTS_WITH_CI(pszBaseURL, "WMS:")) pszBaseURL += 4; - CPLString osLayer = CPLURLGetValue(pszBaseURL, "LAYERS"); + const CPLString osLayer = CPLURLGetValue(pszBaseURL, "LAYERS"); CPLString osVersion = CPLURLGetValue(pszBaseURL, "VERSION"); - CPLString osSRS = CPLURLGetValue(pszBaseURL, "SRS"); - CPLString osCRS = CPLURLGetValue(pszBaseURL, "CRS"); + const CPLString osSRS = CPLURLGetValue(pszBaseURL, "SRS"); + const CPLString osCRS = CPLURLGetValue(pszBaseURL, "CRS"); CPLString osBBOX = CPLURLGetValue(pszBaseURL, "BBOX"); CPLString osFormat = CPLURLGetValue(pszBaseURL, "FORMAT"); - CPLString osTransparent = CPLURLGetValue(pszBaseURL, "TRANSPARENT"); + const CPLString osTransparent = CPLURLGetValue(pszBaseURL, "TRANSPARENT"); /* GDAL specific extensions to alter the default settings */ - CPLString osOverviewCount = CPLURLGetValue(pszBaseURL, "OVERVIEWCOUNT"); - CPLString osTileSize = CPLURLGetValue(pszBaseURL, "TILESIZE"); - CPLString osMinResolution = CPLURLGetValue(pszBaseURL, "MINRESOLUTION"); + const CPLString osOverviewCount = + CPLURLGetValue(pszBaseURL, "OVERVIEWCOUNT"); + const CPLString osTileSize = CPLURLGetValue(pszBaseURL, "TILESIZE"); + const CPLString osMinResolution = + CPLURLGetValue(pszBaseURL, "MINRESOLUTION"); CPLString osBBOXOrder = CPLURLGetValue(pszBaseURL, "BBOXORDER"); CPLString osBaseURL = pszBaseURL; diff --git a/frmts/wms/wmsmetadataset.cpp b/frmts/wms/wmsmetadataset.cpp index 1b510515f3d7..f2dd96dba321 100644 --- a/frmts/wms/wmsmetadataset.cpp +++ b/frmts/wms/wmsmetadataset.cpp @@ -293,7 +293,7 @@ void GDALWMSMetaDataset::AddSubDataset(const char *pszLayerName, void GDALWMSMetaDataset::AddWMSCSubDataset(WMSCTileSetDesc &oWMSCTileSetDesc, const char *pszTitle, - CPLString osTransparent) + const CPLString &osTransparent) { CPLString osSubdatasetName = "WMS:"; osSubdatasetName += osGetURL; @@ -579,7 +579,7 @@ void GDALWMSMetaDataset::ParseWMSCTileSets(CPLXMLNode *psXML) oWMSCTileSet.nTileWidth = nTileWidth; oWMSCTileSet.nTileHeight = nTileHeight; - osMapWMSCTileSet[oWMSCKey] = oWMSCTileSet; + osMapWMSCTileSet[oWMSCKey] = std::move(oWMSCTileSet); } } } diff --git a/frmts/wms/wmsmetadataset.h b/frmts/wms/wmsmetadataset.h index abc4d935f28c..d82283f4d888 100644 --- a/frmts/wms/wmsmetadataset.h +++ b/frmts/wms/wmsmetadataset.h @@ -91,7 +91,8 @@ class GDALWMSMetaDataset final : public GDALPamDataset // WMS-C only void AddWMSCSubDataset(WMSCTileSetDesc &oWMSCTileSetDesc, - const char *pszTitle, CPLString osTransparent); + const char *pszTitle, + const CPLString &osTransparent); // WMS-C only void ParseWMSCTileSets(CPLXMLNode *psXML); diff --git a/frmts/wmts/wmtsdataset.cpp b/frmts/wmts/wmtsdataset.cpp index c3320333c206..1b45b243768d 100644 --- a/frmts/wmts/wmtsdataset.cpp +++ b/frmts/wmts/wmtsdataset.cpp @@ -857,7 +857,7 @@ int WMTSDataset::ReadTMLimits( oTMLimits.nMaxTileRow = atoi(pszMaxTileRow); oTMLimits.nMinTileCol = atoi(pszMinTileCol); oTMLimits.nMaxTileCol = atoi(pszMaxTileCol); - aoMapTileMatrixLimits[pszTileMatrix] = oTMLimits; + aoMapTileMatrixLimits[pszTileMatrix] = std::move(oTMLimits); } return TRUE; } @@ -2160,6 +2160,7 @@ GDALDataset *WMTSDataset::Open(GDALOpenInfo *poOpenInfo) if (!osURLFeatureInfoTemplate.empty()) osURLFeatureInfoTemplate += osExtraQueryParameters; poDS->osURLFeatureInfoTemplate = osURLFeatureInfoTemplate; + CPL_IGNORE_RET_VAL(osURLFeatureInfoTemplate); // Build all TMS datasets, wrapped in VRT datasets for (int i = static_cast(oTMS.aoTM.size() - 1); i >= 0; i--) diff --git a/frmts/xyz/xyzdataset.cpp b/frmts/xyz/xyzdataset.cpp index afa349eecda9..645f4e832f02 100644 --- a/frmts/xyz/xyzdataset.cpp +++ b/frmts/xyz/xyzdataset.cpp @@ -1337,7 +1337,7 @@ GDALDataset *XYZDataset::Open(GDALOpenInfo *poOpenInfo) ++oIter; } } - adfStepX = adfStepXNew; + adfStepX = std::move(adfStepXNew); if (bAddNewValue) { CPLDebug("XYZ", "New stepX=%.15f", dfStepX); diff --git a/frmts/zarr/zarr_array.cpp b/frmts/zarr/zarr_array.cpp index 07b25f6169f5..74b6e6062f2b 100644 --- a/frmts/zarr/zarr_array.cpp +++ b/frmts/zarr/zarr_array.cpp @@ -2064,7 +2064,7 @@ ZarrArray::OpenTilePresenceCache(bool bCanCreate) const if (poTilePresenceArray) { bool ok = true; - const auto apoDimsCache = poTilePresenceArray->GetDimensions(); + const auto &apoDimsCache = poTilePresenceArray->GetDimensions(); if (poTilePresenceArray->GetDataType() != eByteDT || apoDimsCache.size() != m_aoDims.size()) { @@ -2202,7 +2202,7 @@ bool ZarrArray::CacheTilePresence() const std::vector anCount(m_aoDims.size(), 1); const std::vector anArrayStep(m_aoDims.size(), 0); const std::vector anBufferStride(m_aoDims.size(), 0); - const auto apoDimsCache = poTilePresenceArray->GetDimensions(); + const auto &apoDimsCache = poTilePresenceArray->GetDimensions(); const auto eByteDT = GDALExtendedDataType::Create(GDT_Byte); CPLDebug(ZARR_DEBUG_KEY, diff --git a/frmts/zarr/zarr_attribute.cpp b/frmts/zarr/zarr_attribute.cpp index aec2a19ea419..bdde645b8ad4 100644 --- a/frmts/zarr/zarr_attribute.cpp +++ b/frmts/zarr/zarr_attribute.cpp @@ -239,7 +239,7 @@ CPLJSONObject ZarrAttributeGroup::Serialize() const const auto attrs = m_poGroup->GetAttributes(nullptr); for (const auto &attr : attrs) { - const auto oType = attr->GetDataType(); + const auto &oType = attr->GetDataType(); if (oType.GetClass() == GEDTC_STRING) { const auto anDims = attr->GetDimensionsSize(); diff --git a/frmts/zarr/zarr_v2_array.cpp b/frmts/zarr/zarr_v2_array.cpp index 0b8e1f57159c..13af8d80222a 100644 --- a/frmts/zarr/zarr_v2_array.cpp +++ b/frmts/zarr/zarr_v2_array.cpp @@ -940,7 +940,7 @@ bool ZarrV2Array::FlushDirtyTile() const void *out_buffer = &abyCompressedData[0]; size_t out_size = abyCompressedData.size(); CPLStringList aosOptions; - const auto compressorConfig = m_oCompressorJSon; + const auto &compressorConfig = m_oCompressorJSon; for (const auto &obj : compressorConfig.GetChildren()) { aosOptions.SetNameValue(obj.GetName().c_str(), @@ -1632,7 +1632,7 @@ ZarrV2Group::LoadArray(const std::string &osArrayName, poDimParentGroup ->m_oMapDimensions[poDim->GetName()] = - poDimLocal; + std::move(poDimLocal); } } } diff --git a/frmts/zarr/zarr_v2_group.cpp b/frmts/zarr/zarr_v2_group.cpp index eb70ade14516..e3e8d7fe0c94 100644 --- a/frmts/zarr/zarr_v2_group.cpp +++ b/frmts/zarr/zarr_v2_group.cpp @@ -831,7 +831,7 @@ static CPLJSONObject FillDTypeElts(const GDALExtendedDataType &oDataType, subArray.Add(subdtype); array.Add(subArray); } - dtype = array; + dtype = std::move(array); break; } } diff --git a/frmts/zarr/zarr_v3_codec.cpp b/frmts/zarr/zarr_v3_codec.cpp index e5b671f76ab9..b184a209df37 100644 --- a/frmts/zarr/zarr_v3_codec.cpp +++ b/frmts/zarr/zarr_v3_codec.cpp @@ -1015,7 +1015,7 @@ bool ZarrV3CodecSequence::InitFromJson(const CPLJSONObject &oCodecs) { return false; } - oInputArrayMetadata = oOutputArrayMetadata; + oInputArrayMetadata = std::move(oOutputArrayMetadata); eLastType = poCodec->GetOutputType(); osLastCodec = poCodec->GetName(); diff --git a/frmts/zarr/zarrdriver.cpp b/frmts/zarr/zarrdriver.cpp index 7919f7473f68..6d399f312e6d 100644 --- a/frmts/zarr/zarrdriver.cpp +++ b/frmts/zarr/zarrdriver.cpp @@ -404,7 +404,7 @@ GDALDataset *ZarrDataset::Open(GDALOpenInfo *poOpenInfo) { if (osMainArray.empty()) { - poMainArray = poArray; + poMainArray = std::move(poArray); osMainArray = osArrayName; } else @@ -1118,10 +1118,11 @@ GDALDataset *ZarrDataset::Create(const char *pszName, int nXSize, int nYSize, CPLTestBool(CSLFetchNameValueDef(papszOptions, "SINGLE_ARRAY", "YES")); const bool bBandInterleave = EQUAL(CSLFetchNameValueDef(papszOptions, "INTERLEAVE", "BAND"), "BAND"); - std::shared_ptr poBandDim; - if (bSingleArray && nBandsIn > 1) - poBandDim = poRG->CreateDimension("Band", std::string(), std::string(), - nBandsIn); + const std::shared_ptr poBandDim( + (bSingleArray && nBandsIn > 1) + ? poRG->CreateDimension("Band", std::string(), std::string(), + nBandsIn) + : nullptr); const char *pszNonNullArrayName = pszArrayName ? pszArrayName : CPLGetBasename(pszName); diff --git a/fuzzers/gdal_fuzzer.cpp b/fuzzers/gdal_fuzzer.cpp index 9b31b24e964c..495862edd992 100644 --- a/fuzzers/gdal_fuzzer.cpp +++ b/fuzzers/gdal_fuzzer.cpp @@ -121,7 +121,7 @@ static void ExploreArray(const std::shared_ptr &poArray, constexpr size_t MAX_ALLOC = 1000 * 1000 * 1000U; if (pszDriverName && EQUAL(pszDriverName, "GRIB")) { - const auto poDims = poArray->GetDimensions(); + const auto &poDims = poArray->GetDimensions(); if (nDimCount >= 2 && poDims[nDimCount - 2]->GetSize() > MAX_ALLOC / sizeof(double) / poDims[nDimCount - 1]->GetSize()) diff --git a/gcore/gdaljp2metadata.cpp b/gcore/gdaljp2metadata.cpp index 9d2751e676af..59ff1501ba3e 100644 --- a/gcore/gdaljp2metadata.cpp +++ b/gcore/gdaljp2metadata.cpp @@ -871,7 +871,7 @@ int GDALJP2Metadata::GMLSRSLookup(const char *pszURN) if (oSRS.importFromXML(pszDictEntryXML) == OGRERR_NONE) { - m_oSRS = oSRS; + m_oSRS = std::move(oSRS); m_oSRS.SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER); bSuccess = true; } @@ -1021,13 +1021,13 @@ int GDALJP2Metadata::ParseGMLCoverageDesc() /* -------------------------------------------------------------------- */ bool bNeedAxisFlip = false; - OGRSpatialReference oSRS; if (bSuccess && pszSRSName != nullptr && m_oSRS.IsEmpty()) { + OGRSpatialReference oSRS; if (STARTS_WITH_CI(pszSRSName, "epsg:")) { if (oSRS.SetFromUserInput(pszSRSName) == OGRERR_NONE) - m_oSRS = oSRS; + m_oSRS = std::move(oSRS); } else if ((STARTS_WITH_CI(pszSRSName, "urn:") && strstr(pszSRSName, ":def:") != nullptr && @@ -1040,11 +1040,11 @@ int GDALJP2Metadata::ParseGMLCoverageDesc() "http://www.opengis.net/def/crs/") && oSRS.importFromCRSURL(pszSRSName) == OGRERR_NONE)) { - m_oSRS = oSRS; + m_oSRS = std::move(oSRS); // Per #2131 - if (oSRS.EPSGTreatsAsLatLong() || - oSRS.EPSGTreatsAsNorthingEasting()) + if (m_oSRS.EPSGTreatsAsLatLong() || + m_oSRS.EPSGTreatsAsNorthingEasting()) { CPLDebug("GMLJP2", "Request axis flip for SRS=%s", pszSRSName); bNeedAxisFlip = true; @@ -2937,7 +2937,7 @@ GDALJP2Box *GDALJP2Metadata::CreateGMLJP2V2(int nXSize, int nYSize, if (!osXSD.empty()) { GMLJP2V2BoxDesc oDesc; - oDesc.osFile = osXSD; + oDesc.osFile = std::move(osXSD); oDesc.osLabel = CPLGetFilename(oDesc.osFile); osSchemaLocation += papszTokens[0]; osSchemaLocation += " "; diff --git a/gcore/gdaljp2structure.cpp b/gcore/gdaljp2structure.cpp index bbc9e3055197..b3ae58eba05f 100644 --- a/gcore/gdaljp2structure.cpp +++ b/gcore/gdaljp2structure.cpp @@ -1267,8 +1267,8 @@ static CPLXMLNode *DumpJPK2CodeStream(CPLXMLNode *psBox, VSILFILE *fp, { memcpy(&v, pabyMarkerDataIter, 2); CPL_MSBPTR16(&v); - const auto comment = - commentFunc ? commentFunc(v) : std::string(); + const std::string comment(commentFunc ? commentFunc(v) + : std::string()); AddField(psMarker, psLastChild, psDumpContext, name, v, comment.empty() ? nullptr : comment.c_str()); pabyMarkerDataIter += 2; @@ -1292,8 +1292,8 @@ static CPLXMLNode *DumpJPK2CodeStream(CPLXMLNode *psBox, VSILFILE *fp, { memcpy(&v, pabyMarkerDataIter, 4); CPL_MSBPTR32(&v); - const auto comment = - commentFunc ? commentFunc(v) : std::string(); + const std::string comment(commentFunc ? commentFunc(v) + : std::string()); AddField(psMarker, psLastChild, psDumpContext, name, v, comment.empty() ? nullptr : comment.c_str()); pabyMarkerDataIter += 4; diff --git a/gcore/gdalmultidim.cpp b/gcore/gdalmultidim.cpp index bb7fd02018d4..efc83c6e7f24 100644 --- a/gcore/gdalmultidim.cpp +++ b/gcore/gdalmultidim.cpp @@ -825,7 +825,7 @@ bool GDALGroup::CopyFrom(const std::shared_ptr &poDstRootGroup, auto dstDim = CreateDimension(dim->GetName(), dim->GetType(), dim->GetDirection(), dim->GetSize()); EXIT_OR_CONTINUE_IF_NULL(dstDim); - mapExistingDstDims[dim->GetName()] = dstDim; + mapExistingDstDims[dim->GetName()] = std::move(dstDim); auto poIndexingVarSrc(dim->GetIndexingVariable()); if (poIndexingVarSrc) { @@ -1133,7 +1133,7 @@ bool GDALGroup::CopyFrom(const std::shared_ptr &poDstRootGroup, CPLErrorHandlerPusher oHandlerPusher(CPLQuietErrorHandler); CPLErrorStateBackuper oErrorStateBackuper; oCorrespondingDimIter->second->SetIndexingVariable( - dstArray); + std::move(dstArray)); } } @@ -3826,7 +3826,7 @@ bool GDALMDArray::CopyFrom(CPL_UNUSED GDALDataset *poSrcDS, const size_t *chunkCount, GUInt64 iCurChunk, GUInt64 nChunkCount, void *pUserData) { - const auto dt(l_poSrcArray->GetDataType()); + const auto &dt(l_poSrcArray->GetDataType()); auto data = static_cast(pUserData); auto poDstArray = data->poDstArray; if (!l_poSrcArray->Read(chunkArrayStartIdx, chunkCount, nullptr, @@ -6687,11 +6687,12 @@ bool GDALMDArrayMask::Init(CSLConstList papszOptions) } } - const auto adfValues = bHasFlagValues - ? poFlagValues->ReadAsDoubleArray() - : std::vector(); - const auto adfMasks = bHasFlagMasks ? poFlagMasks->ReadAsDoubleArray() - : std::vector(); + const std::vector adfValues( + bHasFlagValues ? poFlagValues->ReadAsDoubleArray() + : std::vector()); + const std::vector adfMasks( + bHasFlagMasks ? poFlagMasks->ReadAsDoubleArray() + : std::vector()); if (bHasFlagValues && adfValues.size() != static_cast(aosFlagMeanings.size())) @@ -8599,7 +8600,7 @@ GDALRasterBandFromArray::GDALRasterBandFromArray( CPLFree(pszTmp); } - const auto unit(indexingVar->GetUnit()); + const auto &unit(indexingVar->GetUnit()); if (!unit.empty()) { SetMetadataItem( @@ -9014,7 +9015,7 @@ GDALDatasetFromArray *GDALDatasetFromArray::Create( osBandArrayFullname.c_str()); return nullptr; } - const auto osAuxArrayDimName = + const auto &osAuxArrayDimName = oItem.poArray->GetDimensions()[0]->GetName(); auto oIter = oMapArrayDimNameToExtraDimIdx.find(osAuxArrayDimName); if (oIter == oMapArrayDimNameToExtraDimIdx.end()) @@ -12612,7 +12613,7 @@ void GDALAttributeFreeRawResult(GDALAttributeH hAttr, GByte *raw, VALIDATE_POINTER0(hAttr, __func__); if (raw) { - const auto dt(hAttr->m_poImpl->GetDataType()); + const auto &dt(hAttr->m_poImpl->GetDataType()); const auto nDTSize(dt.GetSize()); GByte *pabyPtr = raw; const auto nEltCount(hAttr->m_poImpl->GetTotalElementsCount()); @@ -13512,7 +13513,7 @@ void GDALPamMultiDim::Load() if (pszCoordinateEpoch) poSRS->SetCoordinateEpoch(CPLAtof(pszCoordinateEpoch)); - d->m_oMapArray[oKey].poSRS = poSRS; + d->m_oMapArray[oKey].poSRS = std::move(poSRS); } const CPLXMLNode *psStatistics = diff --git a/gcore/gdalmultidim_gridded.cpp b/gcore/gdalmultidim_gridded.cpp index da4366c56618..d57e7f7b562a 100644 --- a/gcore/gdalmultidim_gridded.cpp +++ b/gcore/gdalmultidim_gridded.cpp @@ -793,7 +793,7 @@ GDALMDArray::GetGridded(const std::string &osGridOptions, // CPLDebug("GDAL", "nXSize = %d, nYSize = %d", nXSize, nYSize); std::vector> apoNewDims; - const auto apoSelfDims = GetDimensions(); + const auto &apoSelfDims = GetDimensions(); for (size_t i = 0; i < GetDimensionCount() - 1; ++i) apoNewDims.emplace_back(apoSelfDims[i]); diff --git a/gcore/gdalpython.cpp b/gcore/gdalpython.cpp index a48f16559bb1..6fda83e8d88f 100644 --- a/gcore/gdalpython.cpp +++ b/gcore/gdalpython.cpp @@ -345,7 +345,8 @@ static bool LoadPythonAPI() 0 && S_ISLNK(sStat.st_mode)) { - osPythonBinary = osResolvedFullLink; + osPythonBinary = + std::move(osResolvedFullLink); continue; } diff --git a/gcore/gdalrasterband.cpp b/gcore/gdalrasterband.cpp index 7d2ed8e1f276..cc2beffeb0f3 100644 --- a/gcore/gdalrasterband.cpp +++ b/gcore/gdalrasterband.cpp @@ -8506,7 +8506,7 @@ class GDALMDArrayFromRasterBand final : public GDALMDArray std::string osDirectionX; if (poSRS && poSRS->GetAxesCount() == 2) { - const auto mapping = poSRS->GetDataAxisToSRSAxisMapping(); + const auto &mapping = poSRS->GetDataAxisToSRSAxisMapping(); OGRAxisOrientation eOrientation1 = OAO_Other; poSRS->GetAxis(nullptr, 0, &eOrientation1); OGRAxisOrientation eOrientation2 = OAO_Other; diff --git a/gcore/mdreader/reader_eros.cpp b/gcore/mdreader/reader_eros.cpp index 220dce8224f2..966bc2eef877 100644 --- a/gcore/mdreader/reader_eros.cpp +++ b/gcore/mdreader/reader_eros.cpp @@ -56,11 +56,11 @@ GDALMDReaderEROS::GDALMDReaderEROS(const char *pszPath, { if (STARTS_WITH_CI(osBaseName + i, ".")) { - CPLString osPassFileName = + std::string osPassFileName = CPLFormFilename(osDirName, szMetadataName, "pass"); if (CPLCheckForFile(&osPassFileName[0], papszSiblingFiles)) { - m_osIMDSourceFilename = osPassFileName; + m_osIMDSourceFilename = std::move(osPassFileName); break; } else @@ -69,7 +69,7 @@ GDALMDReaderEROS::GDALMDReaderEROS(const char *pszPath, CPLFormFilename(osDirName, szMetadataName, "PASS"); if (CPLCheckForFile(&osPassFileName[0], papszSiblingFiles)) { - m_osIMDSourceFilename = osPassFileName; + m_osIMDSourceFilename = std::move(osPassFileName); break; } } @@ -79,33 +79,34 @@ GDALMDReaderEROS::GDALMDReaderEROS(const char *pszPath, if (m_osIMDSourceFilename.empty()) { - CPLString osPassFileName = + std::string osPassFileName = CPLFormFilename(osDirName, szMetadataName, "pass"); if (CPLCheckForFile(&osPassFileName[0], papszSiblingFiles)) { - m_osIMDSourceFilename = osPassFileName; + m_osIMDSourceFilename = std::move(osPassFileName); } else { osPassFileName = CPLFormFilename(osDirName, szMetadataName, "PASS"); if (CPLCheckForFile(&osPassFileName[0], papszSiblingFiles)) { - m_osIMDSourceFilename = osPassFileName; + m_osIMDSourceFilename = std::move(osPassFileName); } } } - CPLString osRPCFileName = CPLFormFilename(osDirName, szMetadataName, "rpc"); + std::string osRPCFileName = + CPLFormFilename(osDirName, szMetadataName, "rpc"); if (CPLCheckForFile(&osRPCFileName[0], papszSiblingFiles)) { - m_osRPBSourceFilename = osRPCFileName; + m_osRPBSourceFilename = std::move(osRPCFileName); } else { osRPCFileName = CPLFormFilename(osDirName, szMetadataName, "RPC"); if (CPLCheckForFile(&osRPCFileName[0], papszSiblingFiles)) { - m_osRPBSourceFilename = osRPCFileName; + m_osRPBSourceFilename = std::move(osRPCFileName); } } diff --git a/gcore/mdreader/reader_landsat.cpp b/gcore/mdreader/reader_landsat.cpp index 1c5a08b57e39..947ce6de368f 100644 --- a/gcore/mdreader/reader_landsat.cpp +++ b/gcore/mdreader/reader_landsat.cpp @@ -68,11 +68,11 @@ GDALMDReaderLandsat::GDALMDReaderLandsat(const char *pszPath, // form metadata file name CPLStrlcpy(szMetadataName + i, "_MTL.txt", 9); - CPLString osIMDSourceFilename = + std::string osIMDSourceFilename = CPLFormFilename(pszDirName, szMetadataName, nullptr); if (CPLCheckForFile(&osIMDSourceFilename[0], papszSiblingFiles)) { - m_osIMDSourceFilename = osIMDSourceFilename; + m_osIMDSourceFilename = std::move(osIMDSourceFilename); } else { @@ -81,7 +81,7 @@ GDALMDReaderLandsat::GDALMDReaderLandsat(const char *pszPath, CPLFormFilename(pszDirName, szMetadataName, nullptr); if (CPLCheckForFile(&osIMDSourceFilename[0], papszSiblingFiles)) { - m_osIMDSourceFilename = osIMDSourceFilename; + m_osIMDSourceFilename = std::move(osIMDSourceFilename); } } diff --git a/gcore/mdreader/reader_orb_view.cpp b/gcore/mdreader/reader_orb_view.cpp index 16a45f0e1084..4383604a274b 100644 --- a/gcore/mdreader/reader_orb_view.cpp +++ b/gcore/mdreader/reader_orb_view.cpp @@ -52,11 +52,11 @@ GDALMDReaderOrbView::GDALMDReaderOrbView(const char *pszPath, const char *pszBaseName = CPLGetBasename(pszPath); const char *pszDirName = CPLGetDirname(pszPath); - CPLString osRPBSourceFilename = + std::string osRPBSourceFilename = CPLFormFilename(pszDirName, CPLSPrintf("%s_rpc", pszBaseName), "txt"); if (CPLCheckForFile(&osRPBSourceFilename[0], papszSiblingFiles)) { - m_osRPBSourceFilename = osRPBSourceFilename; + m_osRPBSourceFilename = std::move(osRPBSourceFilename); } else { @@ -64,7 +64,7 @@ GDALMDReaderOrbView::GDALMDReaderOrbView(const char *pszPath, pszDirName, CPLSPrintf("%s_RPC", pszBaseName), "TXT"); if (CPLCheckForFile(&osRPBSourceFilename[0], papszSiblingFiles)) { - m_osRPBSourceFilename = osRPBSourceFilename; + m_osRPBSourceFilename = std::move(osRPBSourceFilename); } } diff --git a/gcore/mdreader/reader_pleiades.cpp b/gcore/mdreader/reader_pleiades.cpp index 3f46aa8d38ef..b455b6482550 100644 --- a/gcore/mdreader/reader_pleiades.cpp +++ b/gcore/mdreader/reader_pleiades.cpp @@ -58,9 +58,9 @@ GDALMDReaderPleiades::GDALMDReaderPleiades(const char *pszPath, const CPLString osDirName = CPLGetDirname(pszPath); - CPLString osIMDSourceFilename = CPLFormFilename( + std::string osIMDSourceFilename = CPLFormFilename( osDirName, CPLSPrintf("DIM_%s", osBaseName.c_str() + 4), "XML"); - CPLString osRPBSourceFilename = CPLFormFilename( + std::string osRPBSourceFilename = CPLFormFilename( osDirName, CPLSPrintf("RPC_%s", osBaseName.c_str() + 4), "XML"); // find last underline @@ -95,7 +95,7 @@ GDALMDReaderPleiades::GDALMDReaderPleiades(const char *pszPath, if (CPLCheckForFile(&osIMDSourceFilename[0], papszSiblingFiles)) { - m_osIMDSourceFilename = osIMDSourceFilename; + m_osIMDSourceFilename = std::move(osIMDSourceFilename); } else { @@ -103,13 +103,13 @@ GDALMDReaderPleiades::GDALMDReaderPleiades(const char *pszPath, CPLFormFilename(osDirName, CPLSPrintf("DIM_%s", sBaseName), "XML"); if (CPLCheckForFile(&osIMDSourceFilename[0], papszSiblingFiles)) { - m_osIMDSourceFilename = osIMDSourceFilename; + m_osIMDSourceFilename = std::move(osIMDSourceFilename); } } if (CPLCheckForFile(&osRPBSourceFilename[0], papszSiblingFiles)) { - m_osRPBSourceFilename = osRPBSourceFilename; + m_osRPBSourceFilename = std::move(osRPBSourceFilename); } else { @@ -117,7 +117,7 @@ GDALMDReaderPleiades::GDALMDReaderPleiades(const char *pszPath, CPLFormFilename(osDirName, CPLSPrintf("RPC_%s", sBaseName), "XML"); if (CPLCheckForFile(&osRPBSourceFilename[0], papszSiblingFiles)) { - m_osRPBSourceFilename = osRPBSourceFilename; + m_osRPBSourceFilename = std::move(osRPBSourceFilename); } } diff --git a/gcore/mdreader/reader_spot.cpp b/gcore/mdreader/reader_spot.cpp index e7f6577a8947..f6b715deb5ea 100644 --- a/gcore/mdreader/reader_spot.cpp +++ b/gcore/mdreader/reader_spot.cpp @@ -51,12 +51,12 @@ GDALMDReaderSpot::GDALMDReaderSpot(const char *pszPath, if (m_osIMDSourceFilename.empty()) { - CPLString osIMDSourceFilename = + std::string osIMDSourceFilename = CPLFormFilename(pszDirName, "METADATA.DIM", nullptr); if (CPLCheckForFile(&osIMDSourceFilename[0], papszSiblingFiles)) { - m_osIMDSourceFilename = osIMDSourceFilename; + m_osIMDSourceFilename = std::move(osIMDSourceFilename); } else { @@ -64,7 +64,7 @@ GDALMDReaderSpot::GDALMDReaderSpot(const char *pszPath, CPLFormFilename(pszDirName, "metadata.dim", nullptr); if (CPLCheckForFile(&osIMDSourceFilename[0], papszSiblingFiles)) { - m_osIMDSourceFilename = osIMDSourceFilename; + m_osIMDSourceFilename = std::move(osIMDSourceFilename); } } } @@ -76,12 +76,12 @@ GDALMDReaderSpot::GDALMDReaderSpot(const char *pszPath, { if (EQUAL(CPLGetFilename(pszPath), "IMAGERY.TIF")) { - CPLString osIMDSourceFilename = + std::string osIMDSourceFilename = CPLSPrintf("%s\\METADATA.DIM", CPLGetPath(pszPath)); if (CPLCheckForFile(&osIMDSourceFilename[0], papszSiblingFiles)) { - m_osIMDSourceFilename = osIMDSourceFilename; + m_osIMDSourceFilename = std::move(osIMDSourceFilename); } else { @@ -89,7 +89,7 @@ GDALMDReaderSpot::GDALMDReaderSpot(const char *pszPath, CPLSPrintf("%s\\metadata.dim", CPLGetPath(pszPath)); if (CPLCheckForFile(&osIMDSourceFilename[0], papszSiblingFiles)) { - m_osIMDSourceFilename = osIMDSourceFilename; + m_osIMDSourceFilename = std::move(osIMDSourceFilename); } } } diff --git a/gnm/gnm_frmts/file/gnmfilenetwork.cpp b/gnm/gnm_frmts/file/gnmfilenetwork.cpp index 3cfdcd95e059..d470c2e1b9fa 100644 --- a/gnm/gnm_frmts/file/gnmfilenetwork.cpp +++ b/gnm/gnm_frmts/file/gnmfilenetwork.cpp @@ -635,7 +635,7 @@ CPLErr GNMFileNetwork::Create(const char *pszFilename, char **papszOptions) return CE_Failure; } - m_oSRS = spatialRef; + m_oSRS = std::move(spatialRef); } int nResult = CheckNetworkExist(pszFilename, papszOptions); diff --git a/gnm/gnmgraph.cpp b/gnm/gnmgraph.cpp index 58a12408aa52..f29db576d521 100644 --- a/gnm/gnmgraph.cpp +++ b/gnm/gnmgraph.cpp @@ -50,7 +50,7 @@ void GNMGraph::AddVertex(GNMGFID nFID) GNMStdVertex stVertex; stVertex.bIsBlocked = false; - m_mstVertices[nFID] = stVertex; + m_mstVertices[nFID] = std::move(stVertex); } void GNMGraph::DeleteVertex(GNMGFID nFID) diff --git a/ogr/ogrsf_frmts/arrow/ogrfeatherlayer.cpp b/ogr/ogrsf_frmts/arrow/ogrfeatherlayer.cpp index 44fb3d7f934f..f9bfb0cb61fa 100644 --- a/ogr/ogrsf_frmts/arrow/ogrfeatherlayer.cpp +++ b/ogr/ogrsf_frmts/arrow/ogrfeatherlayer.cpp @@ -164,7 +164,7 @@ void OGRFeatherLayer::EstablishFeatureDefn() const auto oMapFieldNameToGDALSchemaFieldDefn = LoadGDALSchema(kv_metadata.get()); - const auto fields = m_poSchema->fields(); + const auto &fields = m_poSchema->fields(); for (int i = 0; i < m_poSchema->num_fields(); ++i) { const auto &field = fields[i]; diff --git a/ogr/ogrsf_frmts/arrow_common/ograrrowlayer.hpp b/ogr/ogrsf_frmts/arrow_common/ograrrowlayer.hpp index a07b603d6ade..153361c06b9d 100644 --- a/ogr/ogrsf_frmts/arrow_common/ograrrowlayer.hpp +++ b/ogr/ogrsf_frmts/arrow_common/ograrrowlayer.hpp @@ -356,7 +356,7 @@ inline bool OGRArrowLayer::MapArrowTypeToOGR( const auto timestampType = static_cast(type.get()); eType = OFTDateTime; - const auto osTZ = timestampType->timezone(); + const auto &osTZ = timestampType->timezone(); int nTZFlag = OGRTimezoneToTZFlag(osTZ.c_str(), false); if (nTZFlag == OGR_TZFLAG_UNKNOWN && !osTZ.empty()) { @@ -775,7 +775,7 @@ static bool IsPointType(const std::shared_ptr &type, return false; auto poListType = std::static_pointer_cast(type); const int nOutDimensionality = poListType->list_size(); - const auto osValueFieldName = poListType->value_field()->name(); + const std::string osValueFieldName(poListType->value_field()->name()); if (nOutDimensionality == 2) { bHasZOut = false; diff --git a/ogr/ogrsf_frmts/arrow_common/ograrrowwriterlayer.hpp b/ogr/ogrsf_frmts/arrow_common/ograrrowwriterlayer.hpp index 3be97c7aa576..68b828f95a5b 100644 --- a/ogr/ogrsf_frmts/arrow_common/ograrrowwriterlayer.hpp +++ b/ogr/ogrsf_frmts/arrow_common/ograrrowwriterlayer.hpp @@ -325,8 +325,8 @@ inline void OGRArrowWriterLayer::CreateSchemaCommon() break; } - auto field = arrow::field(poGeomFieldDefn->GetNameRef(), dt, - poGeomFieldDefn->IsNullable()); + std::shared_ptr field(arrow::field( + poGeomFieldDefn->GetNameRef(), dt, poGeomFieldDefn->IsNullable())); if (m_bWriteFieldArrowExtensionName) { auto kvMetadata = field->metadata() @@ -344,7 +344,7 @@ inline void OGRArrowWriterLayer::CreateSchemaCommon() m_aoEnvelopes.resize(m_poFeatureDefn->GetGeomFieldCount()); m_oSetWrittenGeometryTypes.resize(m_poFeatureDefn->GetGeomFieldCount()); - m_poSchema = arrow::schema(fields); + m_poSchema = arrow::schema(std::move(fields)); CPLAssert(m_poSchema); if (bNeedGDALSchema && CPLTestBool(CPLGetConfigOption( @@ -489,7 +489,7 @@ OGRArrowWriterLayer::AddFieldDomain(std::unique_ptr &&domain, return false; } - m_oMapFieldDomainToStringArray[domain->GetName()] = stringArray; + m_oMapFieldDomainToStringArray[domain->GetName()] = std::move(stringArray); m_oMapFieldDomains[domain->GetName()] = std::move(domain); return true; } @@ -2167,7 +2167,7 @@ inline bool OGRArrowWriterLayer::WriteArrowBatchInternal( } } poRecordBatchResult = arrow::RecordBatch::Make( - m_poSchema, poRecordBatch->num_rows(), apoArrays); + m_poSchema, poRecordBatch->num_rows(), std::move(apoArrays)); if (!poRecordBatchResult.ok()) { CPLError(CE_Failure, CPLE_AppDefined, diff --git a/ogr/ogrsf_frmts/cad/libopencad/dwg/r2000.cpp b/ogr/ogrsf_frmts/cad/libopencad/dwg/r2000.cpp index 5f9d1a697026..417427d85353 100644 --- a/ogr/ogrsf_frmts/cad/libopencad/dwg/r2000.cpp +++ b/ogr/ogrsf_frmts/cad/libopencad/dwg/r2000.cpp @@ -738,7 +738,7 @@ int DWGFileR2000::ReadClasses( enum OpenOptions eOptions ) stClass.bWasZombie = buffer.ReadBIT(); stClass.bIsEntity = buffer.ReadBITSHORT() == 0x1F2; - oClasses.addClass( stClass ); + oClasses.addClass( std::move(stClass) ); } buffer.Seek(dSectionBitSize, CADBuffer::BEG); @@ -3409,7 +3409,7 @@ CADDimensionObject * DWGFileR2000::getDimension(short dObjectType, dimension->setSize( dObjectSize ); dimension->stCed = stCommonEntityData; - dimension->cdd = stCDD; + dimension->cdd = std::move(stCDD); CADVector vert10pt = buffer.ReadVector(); dimension->vert10pt = vert10pt; @@ -3438,7 +3438,7 @@ CADDimensionObject * DWGFileR2000::getDimension(short dObjectType, dimension->setSize( dObjectSize ); dimension->stCed = stCommonEntityData; - dimension->cdd = stCDD; + dimension->cdd = std::move(stCDD); CADVector vert13pt = buffer.ReadVector(); dimension->vert13pt = vert13pt; @@ -3468,7 +3468,7 @@ CADDimensionObject * DWGFileR2000::getDimension(short dObjectType, dimension->setSize( dObjectSize ); dimension->stCed = stCommonEntityData; - dimension->cdd = stCDD; + dimension->cdd = std::move(stCDD); CADVector vert13pt = buffer.ReadVector(); dimension->vert13pt = vert13pt; @@ -3497,7 +3497,7 @@ CADDimensionObject * DWGFileR2000::getDimension(short dObjectType, dimension->setSize( dObjectSize ); dimension->stCed = stCommonEntityData; - dimension->cdd = stCDD; + dimension->cdd = std::move(stCDD); CADVector vert10pt = buffer.ReadVector(); dimension->vert10pt = vert10pt; @@ -3527,7 +3527,7 @@ CADDimensionObject * DWGFileR2000::getDimension(short dObjectType, dimension->setSize( dObjectSize ); dimension->stCed = stCommonEntityData; - dimension->cdd = stCDD; + dimension->cdd = std::move(stCDD); CADVector vert16pt = buffer.ReadVector(); dimension->vert16pt = vert16pt; @@ -3560,7 +3560,7 @@ CADDimensionObject * DWGFileR2000::getDimension(short dObjectType, dimension->setSize( dObjectSize ); dimension->stCed = stCommonEntityData; - dimension->cdd = stCDD; + dimension->cdd = std::move(stCDD); CADVector vert10pt = buffer.ReadVector(); dimension->vert10pt = vert10pt; @@ -3586,7 +3586,7 @@ CADDimensionObject * DWGFileR2000::getDimension(short dObjectType, dimension->setSize( dObjectSize ); dimension->stCed = stCommonEntityData; - dimension->cdd = stCDD; + dimension->cdd = std::move(stCDD); CADVector vert15pt = buffer.ReadVector(); dimension->vert15pt = vert15pt; diff --git a/ogr/ogrsf_frmts/csv/ogrcsvlayer.cpp b/ogr/ogrsf_frmts/csv/ogrcsvlayer.cpp index b158e9550dea..d83f2219f318 100644 --- a/ogr/ogrsf_frmts/csv/ogrcsvlayer.cpp +++ b/ogr/ogrsf_frmts/csv/ogrcsvlayer.cpp @@ -338,7 +338,8 @@ void OGRCSVLayer::BuildFeatureDefn(const char *pszNfdcGeomField, const char *pszExt = CPLGetExtension(pszFilename); if (pszExt[0]) { - std::string osCSVTFilename = CPLResetExtension(pszFilename, "csvt"); + const std::string osCSVTFilename = + CPLResetExtension(pszFilename, "csvt"); VSILFILE *fpCSVT = VSIFOpenL(osCSVTFilename.c_str(), "r"); if (fpCSVT != nullptr) { diff --git a/ogr/ogrsf_frmts/dxf/ogrdxf_leader.cpp b/ogr/ogrsf_frmts/dxf/ogrdxf_leader.cpp index c6c5102c4749..739e4cca5b58 100644 --- a/ogr/ogrsf_frmts/dxf/ogrdxf_leader.cpp +++ b/ogr/ogrsf_frmts/dxf/ogrdxf_leader.cpp @@ -1160,7 +1160,7 @@ void OGRDXFLayer::InsertArrowhead(OGRDXFFeature *const poFeature, try { poArrowheadFeature = InsertBlockInline( - CPLGetErrorCounter(), osBlockName, oTransformer, + CPLGetErrorCounter(), osBlockName, std::move(oTransformer), poArrowheadFeature, apoExtraFeatures, true, false); } catch (const std::invalid_argument &) diff --git a/ogr/ogrsf_frmts/dxf/ogrdxfdatasource.cpp b/ogr/ogrsf_frmts/dxf/ogrdxfdatasource.cpp index 5b456620316e..55f622fd3e67 100644 --- a/ogr/ogrsf_frmts/dxf/ogrdxfdatasource.cpp +++ b/ogr/ogrsf_frmts/dxf/ogrdxfdatasource.cpp @@ -449,7 +449,7 @@ bool OGRDXFDataSource::ReadLayerDefinition() } if (!oLayerProperties.empty()) - oLayerTable[osLayerName] = oLayerProperties; + oLayerTable[osLayerName] = std::move(oLayerProperties); if (nCode == 0) UnreadValue(); @@ -545,7 +545,7 @@ bool OGRDXFDataSource::ReadLineTypeDefinition() oLineTypeDef.end()); } - oLineTypeTable[osLineTypeName] = oLineTypeDef; + oLineTypeTable[osLineTypeName] = std::move(oLineTypeDef); } if (nCode == 0) @@ -643,7 +643,7 @@ bool OGRDXFDataSource::ReadTextStyleDefinition() UnreadValue(); if (osStyleHandle != "") - oTextStyleHandles[osStyleHandle] = osStyleName; + oTextStyleHandles[osStyleHandle] = std::move(osStyleName); return true; } @@ -762,7 +762,7 @@ bool OGRDXFDataSource::ReadDimStyleDefinition() } if (!oDimStyleProperties.empty()) - oDimStyleTable[osDimStyleName] = oDimStyleProperties; + oDimStyleTable[osDimStyleName] = std::move(oDimStyleProperties); if (nCode == 0) UnreadValue(); diff --git a/ogr/ogrsf_frmts/dxf/ogrdxflayer.cpp b/ogr/ogrsf_frmts/dxf/ogrdxflayer.cpp index 6d7962ccc5ac..17ceccc47227 100644 --- a/ogr/ogrsf_frmts/dxf/ogrdxflayer.cpp +++ b/ogr/ogrsf_frmts/dxf/ogrdxflayer.cpp @@ -836,7 +836,7 @@ OGRDXFFeature *OGRDXFLayer::TranslateTEXT(const bool bIsAttribOrAttdef) else osEscaped += osText[iC]; } - osText = osEscaped; + osText = std::move(osEscaped); } /* -------------------------------------------------------------------- */ @@ -2884,8 +2884,8 @@ OGRDXFFeature *OGRDXFLayer::InsertBlockInline( { poSubFeature = InsertBlockInline( nInitialErrorCounter, poSubFeature->osBlockName, - oInnerTransformer, poSubFeature, apoInnerExtraFeatures, - true, bMergeGeometry); + std::move(oInnerTransformer), poSubFeature, + apoInnerExtraFeatures, true, bMergeGeometry); } catch (const std::invalid_argument &) { @@ -3281,7 +3281,7 @@ bool OGRDXFLayer::GenerateINSERTFeatures() { poFeature = InsertBlockInline( CPLGetErrorCounter(), m_oInsertState.m_osBlockName, - oTransformer, poFeature, apoExtraFeatures, true, + std::move(oTransformer), poFeature, apoExtraFeatures, true, poDS->ShouldMergeBlockGeometries()); } catch (const std::invalid_argument &) diff --git a/ogr/ogrsf_frmts/dxf/ogrdxfwriterlayer.cpp b/ogr/ogrsf_frmts/dxf/ogrdxfwriterlayer.cpp index 95fdad4b0d8e..3c592547ce15 100644 --- a/ogr/ogrsf_frmts/dxf/ogrdxfwriterlayer.cpp +++ b/ogr/ogrsf_frmts/dxf/ogrdxfwriterlayer.cpp @@ -928,7 +928,7 @@ OGRErr OGRDXFWriterLayer::WritePOLYLINE(OGRFeature *poFeature, if (poDS->oHeaderDS.LookupLineType(osLineType).empty() && oNewLineTypes.count(osLineType) == 0) { - oNewLineTypes[osLineType] = adfDefinition; + oNewLineTypes[osLineType] = std::move(adfDefinition); } WriteValue(6, osLineType); diff --git a/ogr/ogrsf_frmts/edigeo/ogredigeodatasource.cpp b/ogr/ogrsf_frmts/edigeo/ogredigeodatasource.cpp index 9931c22166b7..a1264ccde200 100644 --- a/ogr/ogrsf_frmts/edigeo/ogredigeodatasource.cpp +++ b/ogr/ogrsf_frmts/edigeo/ogredigeodatasource.cpp @@ -369,7 +369,7 @@ int OGREDIGEODataSource::ReadDIC() OGREDIGEOAttributeDef sAttributeDef; sAttributeDef.osLAB = osLAB; sAttributeDef.osTYP = osTYP; - mapAttributes[osRID] = sAttributeDef; + mapAttributes[osRID] = std::move(sAttributeDef); } } @@ -753,7 +753,7 @@ int OGREDIGEODataSource::ReadVEC(const char *pszVECName) feaDesc.aosAttIdVal = aosAttIdVal; feaDesc.osSCP = osSCP; feaDesc.osQUP_RID = osQUP_RID; - mapFEA[osRID] = feaDesc; + mapFEA[osRID] = std::move(feaDesc); } else if (osRTY == "PNO") { diff --git a/ogr/ogrsf_frmts/filegdb/FGdbDatasource.cpp b/ogr/ogrsf_frmts/filegdb/FGdbDatasource.cpp index bd412fff34f5..2bf6a34a0b65 100644 --- a/ogr/ogrsf_frmts/filegdb/FGdbDatasource.cpp +++ b/ogr/ogrsf_frmts/filegdb/FGdbDatasource.cpp @@ -1099,7 +1099,7 @@ bool FGdbDataSource::DeleteFieldDomain(const std::string &name, bool FGdbDataSource::UpdateFieldDomain(std::unique_ptr &&domain, std::string &failureReason) { - const auto domainName = domain->GetName(); + const std::string domainName(domain->GetName()); if (!m_bUpdate) { CPLError(CE_Failure, CPLE_NotSupported, diff --git a/ogr/ogrsf_frmts/filegdb/FGdbDriver.cpp b/ogr/ogrsf_frmts/filegdb/FGdbDriver.cpp index 35ede163053d..7749c314db28 100644 --- a/ogr/ogrsf_frmts/filegdb/FGdbDriver.cpp +++ b/ogr/ogrsf_frmts/filegdb/FGdbDriver.cpp @@ -308,8 +308,7 @@ OGRErr FGdbTransactionManager::StartTransaction(OGRDataSource *&poDSInOut, pConnection->CloseGeodatabase(); - CPLString osEditedName(osName); - osEditedName += ".ogredited"; + const CPLString osEditedName(CPLString(osName).append(".ogredited")); CPLPushErrorHandler(CPLQuietErrorHandler); CPL_IGNORE_RET_VAL(CPLUnlinkTree(osEditedName)); diff --git a/ogr/ogrsf_frmts/filegdb/FGdbLayer.cpp b/ogr/ogrsf_frmts/filegdb/FGdbLayer.cpp index e0f3bd65349b..53e53ab55ab4 100644 --- a/ogr/ogrsf_frmts/filegdb/FGdbLayer.cpp +++ b/ogr/ogrsf_frmts/filegdb/FGdbLayer.cpp @@ -3423,7 +3423,7 @@ void FGdbLayer::ResetReading() EndBulkLoad(); #ifdef WORKAROUND_CRASH_ON_CDF_WITH_BINARY_FIELD - const auto wstrSubFieldBackup = m_wstrSubfields; + const std::wstring wstrSubFieldBackup(m_wstrSubfields); if (!m_apoByteArrays.empty()) { m_bWorkaroundCrashOnCDFWithBinaryField = CPLTestBool(CPLGetConfigOption( diff --git a/ogr/ogrsf_frmts/generic/ogreditablelayer.cpp b/ogr/ogrsf_frmts/generic/ogreditablelayer.cpp index c0963abeb8bf..c688501d788c 100644 --- a/ogr/ogrsf_frmts/generic/ogreditablelayer.cpp +++ b/ogr/ogrsf_frmts/generic/ogreditablelayer.cpp @@ -187,7 +187,11 @@ OGRFeature *OGREditableLayer::Translate(OGRFeatureDefn *poTargetDefn, ->GetNameRef()] = iField; } if (poTargetDefn == m_poEditableFeatureDefn) - m_oMapEditableFDefnFieldNameToIdx = oMapTargetFieldNameToIdx; + { + m_oMapEditableFDefnFieldNameToIdx = + std::move(oMapTargetFieldNameToIdx); + poMap = &m_oMapEditableFDefnFieldNameToIdx; + } } int *panMap = static_cast( diff --git a/ogr/ogrsf_frmts/generic/ogrlayerarrow.cpp b/ogr/ogrsf_frmts/generic/ogrlayerarrow.cpp index df410bc63fb9..55865c74efd1 100644 --- a/ogr/ogrsf_frmts/generic/ogrlayerarrow.cpp +++ b/ogr/ogrsf_frmts/generic/ogrlayerarrow.cpp @@ -2623,7 +2623,7 @@ OGRParseArrowMetadata(const char *pabyMetadata) osValue.assign(pabyMetadata, nSizeValue); pabyMetadata += nSizeValue; - oMetadata[osKey] = osValue; + oMetadata[osKey] = std::move(osValue); } return oMetadata; diff --git a/ogr/ogrsf_frmts/gmlas/ogrgmlasconf.cpp b/ogr/ogrsf_frmts/gmlas/ogrgmlasconf.cpp index 9e0b8b57ccde..caaa11c0bcff 100644 --- a/ogr/ogrsf_frmts/gmlas/ogrgmlasconf.cpp +++ b/ogr/ogrsf_frmts/gmlas/ogrgmlasconf.cpp @@ -227,8 +227,9 @@ static void ParseNamespaces(CPLXMLNode *psContainerNode, if (psIter->eType == CXT_Element && EQUAL(psIter->pszValue, "Namespace")) { - CPLString osPrefix = CPLGetXMLValue(psIter, "prefix", ""); - CPLString osURI = CPLGetXMLValue(psIter, "uri", ""); + const std::string osPrefix = + CPLGetXMLValue(psIter, "prefix", ""); + const std::string osURI = CPLGetXMLValue(psIter, "uri", ""); if (!osPrefix.empty() && !osURI.empty()) { if (oMap.find(osPrefix) == oMap.end()) diff --git a/ogr/ogrsf_frmts/gmlas/ogrgmlasdatasource.cpp b/ogr/ogrsf_frmts/gmlas/ogrgmlasdatasource.cpp index f25dd3ecd85e..87024f3a8b61 100644 --- a/ogr/ogrsf_frmts/gmlas/ogrgmlasdatasource.cpp +++ b/ogr/ogrsf_frmts/gmlas/ogrgmlasdatasource.cpp @@ -401,34 +401,34 @@ void GMLASTopElementParser::startElement(const XMLCh *const /*uri*/, for (unsigned int i = 0; i < attrs.getLength(); i++) { - CPLString osAttrURIPrefix(transcode(attrs.getURI(i))); - CPLString osAttrLocalname(transcode(attrs.getLocalName(i))); - CPLString osAttrValue(transcode(attrs.getValue(i))); + const std::string osAttrURIPrefix(transcode(attrs.getURI(i))); + const std::string osAttrLocalname(transcode(attrs.getLocalName(i))); + const std::string osAttrValue(transcode(attrs.getValue(i))); if (osAttrURIPrefix == szXSI_URI && osAttrLocalname == szSCHEMA_LOCATION) { CPLDebug("GMLAS", "%s=%s", szSCHEMA_LOCATION, osAttrValue.c_str()); - char **papszTokens = CSLTokenizeString2(osAttrValue, " ", 0); - int nTokens = CSLCount(papszTokens); + const CPLStringList aosTokens( + CSLTokenizeString2(osAttrValue.c_str(), " ", 0)); + const int nTokens = aosTokens.size(); if ((nTokens % 2) == 0) { for (int j = 0; j < nTokens; j += 2) { - if (!STARTS_WITH(papszTokens[j], szWFS_URI) && - !(EQUAL(papszTokens[j], szGML_URI) || - STARTS_WITH(papszTokens[j], + if (!STARTS_WITH(aosTokens[j], szWFS_URI) && + !(EQUAL(aosTokens[j], szGML_URI) || + STARTS_WITH(aosTokens[j], (CPLString(szGML_URI) + "/").c_str()))) { CPLDebug("GMLAS", "Schema to analyze: %s -> %s", - papszTokens[j], papszTokens[j + 1]); - m_aoFilenames.push_back(PairURIFilename( - papszTokens[j], papszTokens[j + 1])); + aosTokens[j], aosTokens[j + 1]); + m_aoFilenames.push_back( + PairURIFilename(aosTokens[j], aosTokens[j + 1])); } } } - CSLDestroy(papszTokens); } else if (osAttrURIPrefix == szXSI_URI && osAttrLocalname == szNO_NAMESPACE_SCHEMA_LOCATION) diff --git a/ogr/ogrsf_frmts/gmlas/ogrgmlaslayer.cpp b/ogr/ogrsf_frmts/gmlas/ogrgmlaslayer.cpp index 70479a4ed6a8..ced2f1e144fd 100644 --- a/ogr/ogrsf_frmts/gmlas/ogrgmlaslayer.cpp +++ b/ogr/ogrsf_frmts/gmlas/ogrgmlaslayer.cpp @@ -936,6 +936,8 @@ void OGRGMLASLayer::PostInit(bool bIncludeGeometryXML) [GMLASField::MakeXLinkRawContentFieldXPathFromXLinkHrefXPath( oField.GetXPath())] = m_poFeatureDefn->GetFieldCount() - 1; } + + CPL_IGNORE_RET_VAL(osOGRFieldName); } CreateCompoundFoldedMappings(); @@ -1123,7 +1125,7 @@ void OGRGMLASLayer::InsertNewField(int nInsertPos, OGRFieldDefn &oFieldDefn, else oMapOGRFieldIdxtoFCFieldIdx[oIter.first + 1] = oIter.second; } - m_oMapOGRFieldIdxtoFCFieldIdx = oMapOGRFieldIdxtoFCFieldIdx; + m_oMapOGRFieldIdxtoFCFieldIdx = std::move(oMapOGRFieldIdxtoFCFieldIdx); } OGRLayer *poFieldsMetadataLayer = m_poDS->GetFieldsMetadataLayer(); @@ -1276,15 +1278,15 @@ CPLString OGRGMLASLayer::LaunderFieldName(const CPLString &osFieldName) if (m_poFeatureDefn->GetFieldIndex(osLaunderedName) >= 0) { nCounter = 1; - CPLString osCandidate; + std::string osCandidate; do { nCounter++; osCandidate = OGRGMLASAddSerialNumber( osLaunderedName, nCounter, nCounter + 1, nIdentifierMaxLength); } while (nCounter < 100 && - m_poFeatureDefn->GetFieldIndex(osCandidate) >= 0); - osLaunderedName = osCandidate; + m_poFeatureDefn->GetFieldIndex(osCandidate.c_str()) >= 0); + osLaunderedName = std::move(osCandidate); } return osLaunderedName; diff --git a/ogr/ogrsf_frmts/gmlas/ogrgmlasreader.cpp b/ogr/ogrsf_frmts/gmlas/ogrgmlasreader.cpp index 8b74db874398..c9c0d3e7af54 100644 --- a/ogr/ogrsf_frmts/gmlas/ogrgmlasreader.cpp +++ b/ogr/ogrsf_frmts/gmlas/ogrgmlasreader.cpp @@ -237,7 +237,7 @@ void GMLASErrorHandler::handle(const SAXParseException &e, CPLErr eErr) "http://www.opengis.net/gml/3.2:AbstractCRS' not found") != std::string::npos) { - m_osGMLTypeNotFoundError = osFullErrorMsg; + m_osGMLTypeNotFoundError = std::move(osFullErrorMsg); } else if (m_bHideGMLTypeNotFound && !m_osGMLTypeNotFoundError.empty()) { @@ -3473,7 +3473,7 @@ bool GMLASReader::RunFirstPass( delete poLayer; } } - *m_papoLayers = apoNewLayers; + *m_papoLayers = std::move(apoNewLayers); } if (bRemoveUnusedFields) { diff --git a/ogr/ogrsf_frmts/gmlas/ogrgmlasschemaanalyzer.cpp b/ogr/ogrsf_frmts/gmlas/ogrgmlasschemaanalyzer.cpp index 0d76b6286964..66cdc43c8447 100644 --- a/ogr/ogrsf_frmts/gmlas/ogrgmlasschemaanalyzer.cpp +++ b/ogr/ogrsf_frmts/gmlas/ogrgmlasschemaanalyzer.cpp @@ -1285,7 +1285,7 @@ static CPLString GetAnnotationDoc(const XSElementDeclaration *poEltDecl) break; poTypeDef = poNewTypeDef; } - CPLString osDoc2 = GetAnnotationDoc(list); + const CPLString osDoc2 = GetAnnotationDoc(list); if (!osDoc.empty() && !osDoc2.empty()) { osDoc += "\n"; diff --git a/ogr/ogrsf_frmts/gmlas/ogrgmlaswriter.cpp b/ogr/ogrsf_frmts/gmlas/ogrgmlaswriter.cpp index 3a36ca06e218..f59447d071be 100644 --- a/ogr/ogrsf_frmts/gmlas/ogrgmlaswriter.cpp +++ b/ogr/ogrsf_frmts/gmlas/ogrgmlaswriter.cpp @@ -512,6 +512,7 @@ bool GMLASWriter::Write(GDALProgressFunc pfnProgress, void *pProgressData) else { m_osGMLVersion = osGMLVersion; + CPL_IGNORE_RET_VAL(osGMLVersion); } m_osSRSNameFormat = CSLFetchNameValueDef( @@ -2326,7 +2327,7 @@ bool GMLASWriter::WriteFieldRegular( if (!bWriteEltContent) VSIFPrintfL(m_fpXML, "\""); - aoCurComponents = aoFieldComponents; + aoCurComponents = std::move(aoFieldComponents); bCurIsRegularField = true; return true; @@ -2440,7 +2441,7 @@ bool GMLASWriter::WriteFieldNoLink( */ - aoNewInitialContext = aoFieldComponents; + aoNewInitialContext = std::move(aoFieldComponents); } else if (aoFieldComponents.size() == aoLayerComponents.size() + 2) { @@ -2455,7 +2456,7 @@ bool GMLASWriter::WriteFieldNoLink( */ - aoNewInitialContext = aoFieldComponents; + aoNewInitialContext = std::move(aoFieldComponents); aoNewInitialContext.resize(aoNewInitialContext.size() - 1); } else @@ -2471,7 +2472,7 @@ bool GMLASWriter::WriteFieldNoLink( */ - aoNewInitialContext = aoLayerComponents; + aoNewInitialContext = std::move(aoLayerComponents); } WriteClosingAndStartingTags(aoCurComponents, aoNewInitialContext, @@ -2652,7 +2653,7 @@ bool GMLASWriter::WriteFieldWithLink( const bool bHasChild = poChildFeature != nullptr; if (bHasChild) { - aoInitialComponents = aoFieldComponents; + aoInitialComponents = std::move(aoFieldComponents); if (!aoInitialComponents.empty()) aoInitialComponents.resize(aoInitialComponents.size() - 1); WriteClosingAndStartingTags(aoCurComponents, aoInitialComponents, @@ -2676,7 +2677,7 @@ bool GMLASWriter::WriteFieldWithLink( if (bHasChild) { bAtLeastOneFieldWritten = true; - aoCurComponents = aoInitialComponents; + aoCurComponents = std::move(aoInitialComponents); bCurIsRegularField = false; } @@ -2833,7 +2834,7 @@ bool GMLASWriter::WriteFieldJunctionTable( if (bHasChild) { bAtLeastOneFieldWritten = true; - aoCurComponents = aoInitialComponents; + aoCurComponents = std::move(aoInitialComponents); bCurIsRegularField = false; } diff --git a/ogr/ogrsf_frmts/gmlas/ogrgmlasxpatchmatcher.cpp b/ogr/ogrsf_frmts/gmlas/ogrgmlasxpatchmatcher.cpp index e1c90993ef3e..d7181eed4d61 100644 --- a/ogr/ogrsf_frmts/gmlas/ogrgmlasxpatchmatcher.cpp +++ b/ogr/ogrsf_frmts/gmlas/ogrgmlasxpatchmatcher.cpp @@ -136,7 +136,7 @@ void GMLASXPathMatcher::SetDocumentMapURIToPrefix( } XPathComponent comp; - comp.m_osValue = osCurNode; + comp.m_osValue = std::move(osCurNode); comp.m_bDirectChild = bDirectChild; oVector.push_back(comp); diff --git a/ogr/ogrsf_frmts/gpkg/ogrgeopackagedatasource.cpp b/ogr/ogrsf_frmts/gpkg/ogrgeopackagedatasource.cpp index ec438fb63d20..d62690c35e8f 100644 --- a/ogr/ogrsf_frmts/gpkg/ogrgeopackagedatasource.cpp +++ b/ogr/ogrsf_frmts/gpkg/ogrgeopackagedatasource.cpp @@ -1279,7 +1279,8 @@ GDALGeoPackageDataset::GetContents() oDesc.osMaxX = pszMaxX; if (pszMaxY) oDesc.osMaxY = pszMaxY; - m_oMapTableToContents[CPLString(pszTableName).toupper()] = oDesc; + m_oMapTableToContents[CPLString(pszTableName).toupper()] = + std::move(oDesc); } } diff --git a/ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp b/ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp index 05ab9461a6eb..05e570ca042e 100644 --- a/ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp +++ b/ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp @@ -197,7 +197,7 @@ OGRErr OGRGeoPackageTableLayer::BuildColumns() // Can happen if ignoring all fields on a view... soColumns = "NULL"; } - m_soColumns = soColumns; + m_soColumns = std::move(soColumns); return OGRERR_NONE; } @@ -4957,10 +4957,8 @@ bool OGRGeoPackageTableLayer::HasSpatialIndex() const char *pszT = m_pszTableName; const char *pszC = m_poFeatureDefn->GetGeomFieldDefn(0)->GetNameRef(); - CPLString osRTreeName("rtree_"); - osRTreeName += pszT; - osRTreeName += "_"; - osRTreeName += pszC; + const CPLString osRTreeName( + CPLString("rtree_").append(pszT).append("_").append(pszC)); const std::map &oMap = m_poDS->GetNameTypeMapFromSQliteMaster(); if (oMap.find(CPLString(osRTreeName).toupper()) != oMap.end()) diff --git a/ogr/ogrsf_frmts/gpx/ogrgpxdatasource.cpp b/ogr/ogrsf_frmts/gpx/ogrgpxdatasource.cpp index fc9a35c48ffe..811479fef379 100644 --- a/ogr/ogrsf_frmts/gpx/ogrgpxdatasource.cpp +++ b/ogr/ogrsf_frmts/gpx/ogrgpxdatasource.cpp @@ -292,9 +292,10 @@ void OGRGPXDataSource::startElementValidateCbk(const char *pszNameIn, } if (!osId.empty() && !osDomain.empty()) { - SetMetadataItem( - "AUTHOR_EMAIL", - std::string(osId).append("@").append(osDomain).c_str()); + SetMetadataItem("AUTHOR_EMAIL", std::string(std::move(osId)) + .append("@") + .append(osDomain) + .c_str()); } } else if (strcmp(pszNameIn, "link") == 0) diff --git a/ogr/ogrsf_frmts/hana/ogrhanadatasource.cpp b/ogr/ogrsf_frmts/hana/ogrhanadatasource.cpp index efc8e8fddf6e..2dfb0ea04d23 100644 --- a/ogr/ogrsf_frmts/hana/ogrhanadatasource.cpp +++ b/ogr/ogrsf_frmts/hana/ogrhanadatasource.cpp @@ -1414,7 +1414,7 @@ void OGRHanaDataSource::CreateSpatialReferenceSystem( void OGRHanaDataSource::CreateParseArrayFunctions(const char *schemaName) { auto replaceAll = [](const CPLString &str, const CPLString &before, - const CPLString &after) + const CPLString &after) -> CPLString { CPLString res = str; return res.replaceAll(before, after); diff --git a/ogr/ogrsf_frmts/hana/ogrhanafeaturereader.cpp b/ogr/ogrsf_frmts/hana/ogrhanafeaturereader.cpp index 5283f5aa79cc..7752dd9a687b 100644 --- a/ogr/ogrsf_frmts/hana/ogrhanafeaturereader.cpp +++ b/ogr/ogrsf_frmts/hana/ogrhanafeaturereader.cpp @@ -487,7 +487,7 @@ odbc::String OGRHanaFeatureReader::GetFieldAsDoubleArray(int fieldIndex) const feature_.GetFieldAsDoubleList(fieldIndex, &numElements); return CreateStringFromValues( values, numElements, - [](double value) + [](double value) -> std::string { return std::isnan(value) ? "NULL" : std::to_string(value); }); } diff --git a/ogr/ogrsf_frmts/hana/ogrhanatablelayer.cpp b/ogr/ogrsf_frmts/hana/ogrhanatablelayer.cpp index ab51ad41d0e6..e87270dfdf0d 100644 --- a/ogr/ogrsf_frmts/hana/ogrhanatablelayer.cpp +++ b/ogr/ogrsf_frmts/hana/ogrhanatablelayer.cpp @@ -271,7 +271,7 @@ ColumnTypeInfo ParseColumnTypeInfo(const CPLString &typeDef) CPLError(CE_Failure, CPLE_NotSupported, "Unknown column type '%s'.", typeName.c_str()); - return {typeName, odbc::SQLDataTypes::Unknown, 0, 0}; + return {std::move(typeName), odbc::SQLDataTypes::Unknown, 0, 0}; } CPLString GetColumnDefinition(const ColumnTypeInfo &typeInfo) diff --git a/ogr/ogrsf_frmts/libkml/ogrlibkmldatasource.cpp b/ogr/ogrsf_frmts/libkml/ogrlibkmldatasource.cpp index a1719078d960..ba20dc1a98b0 100644 --- a/ogr/ogrsf_frmts/libkml/ogrlibkmldatasource.cpp +++ b/ogr/ogrsf_frmts/libkml/ogrlibkmldatasource.cpp @@ -425,7 +425,7 @@ bool OGRLIBKMLDataSource::WriteKmz() } } - ParseDocumentOptions(kml, AsDocument(m_poKmlDocKml)); + ParseDocumentOptions(std::move(kml), AsDocument(m_poKmlDocKml)); } std::string oKmlOut = kmldom::SerializePretty(m_poKmlDocKmlRoot); @@ -458,7 +458,7 @@ bool OGRLIBKMLDataSource::WriteKmz() poKmlDocument->add_schema(std::move(poKmlSchema)); } - papoLayers[iLayer]->Finalize(poKmlDocument); + papoLayers[iLayer]->Finalize(std::move(poKmlDocument)); } // If we do not have the layers root @@ -550,7 +550,7 @@ bool OGRLIBKMLDataSource::WriteDir() kml->set_feature(m_poKmlDocKml); } - ParseDocumentOptions(kml, AsDocument(m_poKmlDocKml)); + ParseDocumentOptions(std::move(kml), AsDocument(m_poKmlDocKml)); } std::string oKmlOut = kmldom::SerializePretty(m_poKmlDocKmlRoot); @@ -588,7 +588,7 @@ bool OGRLIBKMLDataSource::WriteDir() poKmlDocument->add_schema(std::move(poKmlSchema)); } - papoLayers[iLayer]->Finalize(poKmlDocument); + papoLayers[iLayer]->Finalize(std::move(poKmlDocument)); } // If we do not have the layers root @@ -854,7 +854,8 @@ OGRLIBKMLLayer *OGRLIBKMLDataSource::AddLayer( /***** add the layer to the array *****/ const int iLayer = nLayers++; papoLayers[iLayer] = poOgrLayer; - m_oMapLayers[CPLString(osUniqueLayername).toupper()] = poOgrLayer; + osUniqueLayername.toupper(); + m_oMapLayers[std::move(osUniqueLayername)] = poOgrLayer; return poOgrLayer; } @@ -984,7 +985,7 @@ static ContainerPtr GetContainerFromRoot(KmlFactory *poKmlFactory, } else if (poKmlRoot->IsA(kmldom::Type_Container)) { - poKmlContainer = AsContainer(poKmlRoot); + poKmlContainer = AsContainer(std::move(poKmlRoot)); } } @@ -1011,12 +1012,13 @@ int OGRLIBKMLDataSource::ParseIntoStyleTable(std::string *poKmlStyleKml, ContainerPtr poKmlContainer = nullptr; - if (!(poKmlContainer = GetContainerFromRoot(m_poKmlFactory, poKmlRoot))) + if (!(poKmlContainer = + GetContainerFromRoot(m_poKmlFactory, std::move(poKmlRoot)))) { return false; } - ParseStyles(AsDocument(poKmlContainer), &m_poStyleTable); + ParseStyles(AsDocument(std::move(poKmlContainer)), &m_poStyleTable); pszStylePath = CPLStrdup(pszMyStylePath); return true; @@ -1266,12 +1268,12 @@ int OGRLIBKMLDataSource::OpenKmz(const char *pszFilename, int bUpdateIn) /***** create the layer *****/ AddLayer(CPLGetBasename(poKmlHref->get_path().c_str()), - wkbUnknown, nullptr, this, poKmlLyrRoot, + wkbUnknown, nullptr, this, std::move(poKmlLyrRoot), poKmlLyrContainer, poKmlHref->get_path().c_str(), FALSE, bUpdateIn, static_cast(nKmlFeatures)); /***** check if any features are another layer *****/ - ParseLayers(poKmlLyrContainer, true); + ParseLayers(std::move(poKmlLyrContainer), true); } } @@ -1311,11 +1313,11 @@ int OGRLIBKMLDataSource::OpenKmz(const char *pszFilename, int bUpdateIn) } AddLayer(layername_default.c_str(), wkbUnknown, nullptr, this, - poKmlDocKmlRoot, poKmlContainer, pszFilename, FALSE, - bUpdateIn, 1); + std::move(poKmlDocKmlRoot), poKmlContainer, pszFilename, + FALSE, bUpdateIn, 1); } - ParseLayers(poKmlContainer, true); + ParseLayers(std::move(poKmlContainer), true); } /***** read the style table if it has one *****/ @@ -1423,11 +1425,11 @@ int OGRLIBKMLDataSource::OpenDir(const char *pszFilename, int bUpdateIn) /***** create the layer *****/ AddLayer(CPLGetBasename(osFilePath.c_str()), wkbUnknown, nullptr, this, - poKmlRoot, poKmlContainer, osFilePath.c_str(), FALSE, - bUpdateIn, nFiles); + std::move(poKmlRoot), poKmlContainer, osFilePath.c_str(), + FALSE, bUpdateIn, nFiles); /***** check if any features are another layer *****/ - ParseLayers(poKmlContainer, true); + ParseLayers(std::move(poKmlContainer), true); } CSLDestroy(papszDirList); @@ -1764,7 +1766,7 @@ void OGRLIBKMLDataSource::ParseDocumentOptions(KmlPtr poKml, LinkSnippetPtr linksnippet = m_poKmlFactory->CreateLinkSnippet(); linksnippet->set_text(pszNLCLinkSnippet); - nlc->set_linksnippet(linksnippet); + nlc->set_linksnippet(std::move(linksnippet)); } if (pszNLCExpires != nullptr) { diff --git a/ogr/ogrsf_frmts/libkml/ogrlibkmllayer.cpp b/ogr/ogrsf_frmts/libkml/ogrlibkmllayer.cpp index a448415cd40a..40211bdebf4f 100644 --- a/ogr/ogrsf_frmts/libkml/ogrlibkmllayer.cpp +++ b/ogr/ogrsf_frmts/libkml/ogrlibkmllayer.cpp @@ -340,7 +340,7 @@ OGRLIBKMLLayer::OGRLIBKMLLayer( { m_poKmlSchema = nullptr; } - kml2FeatureDef(schema, + kml2FeatureDef(std::move(schema), m_poOgrFeatureDefn); } } diff --git a/ogr/ogrsf_frmts/libkml/ogrlibkmlstyle.cpp b/ogr/ogrsf_frmts/libkml/ogrlibkmlstyle.cpp index 699719a2f128..2a8d79bcd46e 100644 --- a/ogr/ogrsf_frmts/libkml/ogrlibkmlstyle.cpp +++ b/ogr/ogrsf_frmts/libkml/ogrlibkmlstyle.cpp @@ -851,8 +851,8 @@ static StyleSelectorPtr StyleFromStyleURL(const StyleMapPtr &stylemap, kmldom::KmlFactory *poKmlFactory = kmldom::KmlFactory::GetFactory(); ContainerPtr poKmlContainer; - if (!(poKmlContainer = - MyGetContainerFromRoot(poKmlFactory, poKmlRoot))) + if (!(poKmlContainer = MyGetContainerFromRoot( + poKmlFactory, std::move(poKmlRoot)))) { CPLFree(pszUrlTmp); CPLFree(pszUrl); diff --git a/ogr/ogrsf_frmts/mem/ogrmemdatasource.cpp b/ogr/ogrsf_frmts/mem/ogrmemdatasource.cpp index 00ba2c9bc327..d1f55d12274a 100644 --- a/ogr/ogrsf_frmts/mem/ogrmemdatasource.cpp +++ b/ogr/ogrsf_frmts/mem/ogrmemdatasource.cpp @@ -175,7 +175,7 @@ bool OGRMemDataSource::AddFieldDomain(std::unique_ptr &&domain, failureReason = "A domain of identical name already exists"; return false; } - const auto domainName = domain->GetName(); + const std::string domainName(domain->GetName()); m_oMapFieldDomains[domainName] = std::move(domain); return true; } @@ -221,7 +221,7 @@ bool OGRMemDataSource::DeleteFieldDomain(const std::string &name, bool OGRMemDataSource::UpdateFieldDomain( std::unique_ptr &&domain, std::string &failureReason) { - const auto domainName = domain->GetName(); + const std::string domainName(domain->GetName()); const auto iter = m_oMapFieldDomains.find(domainName); if (iter == m_oMapFieldDomains.end()) { diff --git a/ogr/ogrsf_frmts/mvt/ogrmvtdataset.cpp b/ogr/ogrsf_frmts/mvt/ogrmvtdataset.cpp index c4048fea586b..e525c80ce1a0 100644 --- a/ogr/ogrsf_frmts/mvt/ogrmvtdataset.cpp +++ b/ogr/ogrsf_frmts/mvt/ogrmvtdataset.cpp @@ -2535,8 +2535,8 @@ GDALDataset *OGRMVTDataset::OpenDirectory(GDALOpenInfo *poOpenInfo) osMetadataFile = pszMetadataFile; } - CPLString osTileExtension(CSLFetchNameValueDef(poOpenInfo->papszOpenOptions, - "TILE_EXTENSION", "pbf")); + const CPLString osTileExtension(CSLFetchNameValueDef( + poOpenInfo->papszOpenOptions, "TILE_EXTENSION", "pbf")); bool bJsonField = CPLFetchBool(poOpenInfo->papszOpenOptions, "JSON_FIELD", false); VSIStatBufL sStat; @@ -4833,7 +4833,7 @@ void OGRMVTWriterDataset::EncodeFeature( } nFeaturesInTile++; - poTargetLayer->addFeature(poFeature); + poTargetLayer->addFeature(std::move(poFeature)); } } } @@ -4887,7 +4887,7 @@ std::string OGRMVTWriterDataset::EncodeTile( MVTLayerProperties props; props.m_nMinZoom = nZ; props.m_nMaxZoom = nZ; - oMapLayerProps[pszLayerName] = props; + oMapLayerProps[pszLayerName] = std::move(props); poLayerProperties = &(oMapLayerProps[pszLayerName]); } } diff --git a/ogr/ogrsf_frmts/openfilegdb/filegdbtable.cpp b/ogr/ogrsf_frmts/openfilegdb/filegdbtable.cpp index 3652e764b7e2..9d0f19f9b2bc 100644 --- a/ogr/ogrsf_frmts/openfilegdb/filegdbtable.cpp +++ b/ogr/ogrsf_frmts/openfilegdb/filegdbtable.cpp @@ -894,7 +894,7 @@ bool FileGDBTable::Open(const char *pszFilename, bool bUpdate, pabyIter++; nRemaining--; returnErrorIf(nCarCount > nRemaining / 2); - std::string osName(ReadUTF16String(pabyIter, nCarCount)); + const std::string osName(ReadUTF16String(pabyIter, nCarCount)); pabyIter += 2 * nCarCount; nRemaining -= 2 * nCarCount; @@ -903,7 +903,7 @@ bool FileGDBTable::Open(const char *pszFilename, bool bUpdate, pabyIter++; nRemaining--; returnErrorIf(nCarCount > nRemaining / 2); - std::string osAlias(ReadUTF16String(pabyIter, nCarCount)); + const std::string osAlias(ReadUTF16String(pabyIter, nCarCount)); pabyIter += 2 * nCarCount; nRemaining -= 2 * nCarCount; diff --git a/ogr/ogrsf_frmts/openfilegdb/gdalopenfilegdbrasterband.cpp b/ogr/ogrsf_frmts/openfilegdb/gdalopenfilegdbrasterband.cpp index 9ccc542bb107..6a0119005011 100644 --- a/ogr/ogrsf_frmts/openfilegdb/gdalopenfilegdbrasterband.cpp +++ b/ogr/ogrsf_frmts/openfilegdb/gdalopenfilegdbrasterband.cpp @@ -477,7 +477,7 @@ bool OGROpenFileGDBDataSource::OpenRaster(const GDALOpenInfo *poOpenInfo, { const auto poFieldRaster = static_cast(poField); - const auto osWKT = poFieldRaster->GetWKT(); + const auto &osWKT = poFieldRaster->GetWKT(); if (!osWKT.empty() && osWKT[0] != '{') { auto poSRS = BuildSRS(osWKT.c_str()); diff --git a/ogr/ogrsf_frmts/openfilegdb/ogropenfilegdbdatasource_write.cpp b/ogr/ogrsf_frmts/openfilegdb/ogropenfilegdbdatasource_write.cpp index 2cb4bf294fe2..c7e7fc7eacf0 100644 --- a/ogr/ogrsf_frmts/openfilegdb/ogropenfilegdbdatasource_write.cpp +++ b/ogr/ogrsf_frmts/openfilegdb/ogropenfilegdbdatasource_write.cpp @@ -1883,7 +1883,7 @@ bool OGROpenFileGDBDataSource::AddRelationship( std::unique_ptr &&relationship, std::string &failureReason) { - const auto relationshipName = relationship->GetName(); + const std::string relationshipName(relationship->GetName()); if (eAccess != GA_Update) { CPLError(CE_Failure, CPLE_NotSupported, @@ -2161,7 +2161,7 @@ bool OGROpenFileGDBDataSource::UpdateRelationship( std::unique_ptr &&relationship, std::string &failureReason) { - const auto relationshipName = relationship->GetName(); + const std::string relationshipName(relationship->GetName()); if (eAccess != GA_Update) { CPLError(CE_Failure, CPLE_NotSupported, diff --git a/ogr/ogrsf_frmts/osm/ogrosmdatasource.cpp b/ogr/ogrsf_frmts/osm/ogrosmdatasource.cpp index d19204503320..f6998dd3d6c9 100644 --- a/ogr/ogrsf_frmts/osm/ogrosmdatasource.cpp +++ b/ogr/ogrsf_frmts/osm/ogrosmdatasource.cpp @@ -4147,19 +4147,18 @@ bool OGROSMDataSource::TransferToDiskIfNecesserary() CloseDB(); - CPLString osNewTmpDBName; - - osNewTmpDBName = CPLGenerateTempFilename("osm_tmp"); + const std::string osNewTmpDBName( + CPLGenerateTempFilename("osm_tmp")); CPLDebug("OSM", "%s too big for RAM. Transferring it onto disk in %s", m_osTmpDBName.c_str(), osNewTmpDBName.c_str()); - if (CPLCopyFile(osNewTmpDBName, m_osTmpDBName) != 0) + if (CPLCopyFile(osNewTmpDBName.c_str(), m_osTmpDBName) != 0) { CPLError(CE_Failure, CPLE_AppDefined, "Cannot copy %s to %s", m_osTmpDBName.c_str(), osNewTmpDBName.c_str()); - VSIUnlink(osNewTmpDBName); + VSIUnlink(osNewTmpDBName.c_str()); m_bStopParsing = true; return false; } diff --git a/ogr/ogrsf_frmts/parquet/ogrparquetdatasetlayer.cpp b/ogr/ogrsf_frmts/parquet/ogrparquetdatasetlayer.cpp index f98177b602d1..571dca353072 100644 --- a/ogr/ogrsf_frmts/parquet/ogrparquetdatasetlayer.cpp +++ b/ogr/ogrsf_frmts/parquet/ogrparquetdatasetlayer.cpp @@ -69,7 +69,7 @@ void OGRParquetDatasetLayer::EstablishFeatureDefn() LoadGDALMetadata(kv_metadata.get()); - const auto fields = m_poSchema->fields(); + const auto &fields = m_poSchema->fields(); for (int i = 0; i < m_poSchema->num_fields(); ++i) { const auto &field = fields[i]; diff --git a/ogr/ogrsf_frmts/parquet/ogrparquetdriver.cpp b/ogr/ogrsf_frmts/parquet/ogrparquetdriver.cpp index 7cf13547e261..a2fcaa079e6f 100644 --- a/ogr/ogrsf_frmts/parquet/ogrparquetdriver.cpp +++ b/ogr/ogrsf_frmts/parquet/ogrparquetdriver.cpp @@ -354,7 +354,7 @@ OpenParquetDatasetWithoutMetadata(const std::string &osBasePathIn, std::shared_ptr factory; PARQUET_ASSIGN_OR_THROW( factory, arrow::dataset::FileSystemDatasetFactory::Make( - std::move(fs), selector, + std::move(fs), std::move(selector), std::make_shared(), std::move(options))); @@ -520,8 +520,8 @@ static GDALDataset *OGRParquetDriverOpen(GDALOpenInfo *poOpenInfo) std::unique_ptr arrow_reader; auto poMemoryPool = std::shared_ptr( arrow::MemoryPool::CreateDefault().release()); - auto st = - parquet::arrow::OpenFile(infile, poMemoryPool.get(), &arrow_reader); + auto st = parquet::arrow::OpenFile(std::move(infile), + poMemoryPool.get(), &arrow_reader); if (!st.ok()) { CPLError(CE_Failure, CPLE_AppDefined, diff --git a/ogr/ogrsf_frmts/parquet/ogrparquetlayer.cpp b/ogr/ogrsf_frmts/parquet/ogrparquetlayer.cpp index ae65d7370c29..4ce27f5a4876 100644 --- a/ogr/ogrsf_frmts/parquet/ogrparquetlayer.cpp +++ b/ogr/ogrsf_frmts/parquet/ogrparquetlayer.cpp @@ -457,7 +457,7 @@ void OGRParquetLayer::EstablishFeatureDefn() return; } - const auto fields = m_poSchema->fields(); + const auto &fields = m_poSchema->fields(); const auto poParquetSchema = metadata->schema(); int iParquetCol = 0; for (int i = 0; i < m_poSchema->num_fields(); ++i) @@ -552,7 +552,7 @@ bool OGRParquetLayer::CheckMatchArrowParquetColumnNames( const auto metadata = m_poArrowReader->parquet_reader()->metadata(); const auto poParquetSchema = metadata->schema(); const int nParquetColumns = poParquetSchema->num_columns(); - const auto fieldName = field->name(); + const auto &fieldName = field->name(); const int iParquetColBefore = iParquetCol; while (iParquetCol < nParquetColumns) diff --git a/ogr/ogrsf_frmts/pgeo/ogrpgeodatasource.cpp b/ogr/ogrsf_frmts/pgeo/ogrpgeodatasource.cpp index b430620bc027..c516bca49ca2 100644 --- a/ogr/ogrsf_frmts/pgeo/ogrpgeodatasource.cpp +++ b/ogr/ogrsf_frmts/pgeo/ogrpgeodatasource.cpp @@ -297,7 +297,7 @@ int OGRPGeoDataSource::Open(GDALOpenInfo *poOpenInfo) { if (auto poDomain = ParseXMLFieldDomainDef(osDefinition)) { - const auto domainName = poDomain->GetName(); + const std::string domainName(poDomain->GetName()); m_oMapFieldDomains[domainName] = std::move(poDomain); } } diff --git a/ogr/ogrsf_frmts/pmtiles/ogrpmtilesfrommbtiles.cpp b/ogr/ogrsf_frmts/pmtiles/ogrpmtilesfrommbtiles.cpp index d06c65996316..47d2e2a28289 100644 --- a/ogr/ogrsf_frmts/pmtiles/ogrpmtilesfrommbtiles.cpp +++ b/ogr/ogrsf_frmts/pmtiles/ogrpmtilesfrommbtiles.cpp @@ -475,8 +475,9 @@ bool OGRPMTilesConvertFromMBTiles(const char *pszDestName, } }; - const auto oCompressFunc = - [psCompressor, &osCompressed](const std::string &osBytes, uint8_t) + const auto oCompressFunc = [psCompressor, + &osCompressed](const std::string &osBytes, + uint8_t) -> std::string { osCompressed.resize(32 + osBytes.size() * 2); size_t nOutputSize = osCompressed.size(); diff --git a/ogr/ogrsf_frmts/shape/ogrshapedatasource.cpp b/ogr/ogrsf_frmts/shape/ogrshapedatasource.cpp index 448c16dd97ba..d1c346d140ff 100644 --- a/ogr/ogrsf_frmts/shape/ogrshapedatasource.cpp +++ b/ogr/ogrsf_frmts/shape/ogrshapedatasource.cpp @@ -1569,7 +1569,7 @@ bool OGRShapeDataSource::UncompressIfNeeded() } } - m_osTemporaryUnzipDir = osTemporaryDir; + m_osTemporaryUnzipDir = std::move(osTemporaryDir); for (int i = 0; i < nLayers; i++) { diff --git a/ogr/ogrsf_frmts/shape/ogrshapelayer.cpp b/ogr/ogrsf_frmts/shape/ogrshapelayer.cpp index 3ffcb7cb9554..24ec18039572 100644 --- a/ogr/ogrsf_frmts/shape/ogrshapelayer.cpp +++ b/ogr/ogrsf_frmts/shape/ogrshapelayer.cpp @@ -559,7 +559,7 @@ CPLString OGRShapeLayer::ConvertCodePage(const char *pszCodePage) if (pszCodePage == nullptr) return l_osEncoding; - CPLString osEncodingFromLDID; + std::string osEncodingFromLDID; if (hDBF->iLanguageDriver != 0) { SetMetadataItem("LDID_VALUE", CPLSPrintf("%d", hDBF->iLanguageDriver), @@ -573,7 +573,7 @@ CPLString OGRShapeLayer::ConvertCodePage(const char *pszCodePage) "SHAPEFILE"); } - CPLString osEncodingFromCPG; + std::string osEncodingFromCPG; if (!STARTS_WITH_CI(pszCodePage, "LDID/")) { SetMetadataItem("CPG_VALUE", pszCodePage, "SHAPEFILE"); @@ -581,14 +581,14 @@ CPLString OGRShapeLayer::ConvertCodePage(const char *pszCodePage) osEncodingFromCPG = GetEncodingFromCPG(pszCodePage); if (!osEncodingFromCPG.empty()) - SetMetadataItem("ENCODING_FROM_CPG", osEncodingFromCPG, + SetMetadataItem("ENCODING_FROM_CPG", osEncodingFromCPG.c_str(), "SHAPEFILE"); - l_osEncoding = osEncodingFromCPG; + l_osEncoding = std::move(osEncodingFromCPG); } else if (!osEncodingFromLDID.empty()) { - l_osEncoding = osEncodingFromLDID; + l_osEncoding = std::move(osEncodingFromLDID); } return l_osEncoding; diff --git a/ogr/ogrsf_frmts/sosi/ogrsosilayer.cpp b/ogr/ogrsf_frmts/sosi/ogrsosilayer.cpp index a9b8ce1c31f9..03a9a9213577 100644 --- a/ogr/ogrsf_frmts/sosi/ogrsosilayer.cpp +++ b/ogr/ogrsf_frmts/sosi/ogrsosilayer.cpp @@ -229,10 +229,7 @@ OGRFeature *OGRSOSILayer::GetNextFeature() newAppendOsValue.append(CPLString(pszPos + 1)); // the new value - oHeaders[osKey] = newAppendOsValue; - - // printf ("Append value for %s is %s \n", osKey.c_str(), - // newAppendOsValue.c_str()); + oHeaders[osKey] = std::move(newAppendOsValue); } else { diff --git a/ogr/ogrsf_frmts/sxf/ogrsxflayer.cpp b/ogr/ogrsf_frmts/sxf/ogrsxflayer.cpp index 3de481a39d6f..68277834855a 100644 --- a/ogr/ogrsf_frmts/sxf/ogrsxflayer.cpp +++ b/ogr/ogrsf_frmts/sxf/ogrsxflayer.cpp @@ -108,9 +108,7 @@ void OGRSXFLayer::AddClassifyCode(unsigned nClassCode, const char *szName) } else { - CPLString szIdName; - szIdName.Printf("%d", nClassCode); - mnClassificators[nClassCode] = szIdName; + mnClassificators[nClassCode] = CPLString().Printf("%d", nClassCode); } } diff --git a/ogr/ogrsf_frmts/vdv/ogrvdvdatasource.cpp b/ogr/ogrsf_frmts/vdv/ogrvdvdatasource.cpp index a06c06db5aea..a792d4c949f5 100644 --- a/ogr/ogrsf_frmts/vdv/ogrvdvdatasource.cpp +++ b/ogr/ogrsf_frmts/vdv/ogrvdvdatasource.cpp @@ -1193,7 +1193,7 @@ GDALDataset *OGRVDVDataSource::Open(GDALOpenInfo *poOpenInfo) if (EQUAL(*papszIter, ".") || EQUAL(*papszIter, "..")) continue; nFiles++; - CPLString osExtension(CPLGetExtension(*papszIter)); + const std::string osExtension(CPLGetExtension(*papszIter)); int nCount = ++oMapOtherExtensions[osExtension]; if (osMajorityExtension == "" || nCount > oMapOtherExtensions[osMajorityExtension]) diff --git a/ogr/ogrsf_frmts/wfs/ogroapifdriver.cpp b/ogr/ogrsf_frmts/wfs/ogroapifdriver.cpp index 4eb066a26d46..3b957b95a234 100644 --- a/ogr/ogrsf_frmts/wfs/ogroapifdriver.cpp +++ b/ogr/ogrsf_frmts/wfs/ogroapifdriver.cpp @@ -1557,7 +1557,7 @@ static bool BuildExampleRecursively(CPLJSONObject &oRes, oArray.Add(oChildRes); } } - oRes = oArray; + oRes = std::move(oArray); return true; } else if (osType == "string") @@ -2527,13 +2527,11 @@ CPLString OGROAPIFLayer::BuildFilter(const swq_expr_node *poNode) m_aoSetQueryableAttributes.find(poFieldDefn->GetNameRef()) != m_aoSetQueryableAttributes.end()) { - CPLString osEscapedFieldName; - { - char *pszEscapedFieldName = - CPLEscapeString(poFieldDefn->GetNameRef(), -1, CPLES_URL); - osEscapedFieldName = pszEscapedFieldName; - CPLFree(pszEscapedFieldName); - } + char *pszEscapedFieldName = + CPLEscapeString(poFieldDefn->GetNameRef(), -1, CPLES_URL); + const CPLString osEscapedFieldName(pszEscapedFieldName); + CPLFree(pszEscapedFieldName); + if (poNode->papoSubExpr[1]->field_type == SWQ_STRING) { char *pszEscapedValue = CPLEscapeString( diff --git a/ogr/ogrsf_frmts/wfs/ogrwfslayer.cpp b/ogr/ogrsf_frmts/wfs/ogrwfslayer.cpp index f91c37e73b08..ee32612da871 100644 --- a/ogr/ogrsf_frmts/wfs/ogrwfslayer.cpp +++ b/ogr/ogrsf_frmts/wfs/ogrwfslayer.cpp @@ -919,8 +919,8 @@ GDALDataset *OGRWFSLayer::FetchGetFeature(int nRequestMaxFeatures) if (psResult->pszContentType) pszContentType = psResult->pszContentType; - CPLString osTmpDirName = CPLSPrintf("/vsimem/tempwfs_%p", this); - VSIMkdir(osTmpDirName, 0); + const std::string osTmpDirName = CPLSPrintf("/vsimem/tempwfs_%p", this); + VSIMkdir(osTmpDirName.c_str(), 0); GByte *pabyData = psResult->pabyData; int nDataLen = psResult->nDataLen; @@ -931,8 +931,8 @@ GDALDataset *OGRWFSLayer::FetchGetFeature(int nRequestMaxFeatures) CPLHTTPParseMultipartMime(psResult)) { bIsMultiPart = true; - OGRWFSRecursiveUnlink(osTmpDirName); - VSIMkdir(osTmpDirName, 0); + OGRWFSRecursiveUnlink(osTmpDirName.c_str()); + VSIMkdir(osTmpDirName.c_str(), 0); for (int i = 0; i < psResult->nMimePartCount; i++) { CPLString osTmpFileName = osTmpDirName + "/"; diff --git a/port/cpl_vsi_mem.cpp b/port/cpl_vsi_mem.cpp index fcdd6a6dc8dd..caa1cc11fea5 100644 --- a/port/cpl_vsi_mem.cpp +++ b/port/cpl_vsi_mem.cpp @@ -764,6 +764,7 @@ int VSIMemFilesystemHandler::Mkdir(const char *pszPathname, long /* nMode */) CPLDebug("VSIMEM", "Mkdir on %s: ref_count=%d", pszPathname, static_cast(poFile.use_count())); #endif + CPL_IGNORE_RET_VAL(poFile); return 0; } @@ -1056,7 +1057,7 @@ VSILFILE *VSIFileFromMemBuffer(const char *pszFilename, GByte *pabyData, /* -------------------------------------------------------------------- */ VSIMemHandle *poHandle = new VSIMemHandle; - poHandle->poFile = poFile; + poHandle->poFile = std::move(poFile); poHandle->bUpdate = true; return poHandle; } diff --git a/port/cpl_vsil_adls.cpp b/port/cpl_vsil_adls.cpp index b2f399b6b74f..e1e0b47bfe41 100644 --- a/port/cpl_vsil_adls.cpp +++ b/port/cpl_vsil_adls.cpp @@ -2147,8 +2147,8 @@ VSIDIR *VSIADLSFSHandler::OpenDir(const char *pszPath, int nRecurseDepth, dir->m_poFS = this; dir->m_bRecursiveRequestFromAccountRoot = osFilesystem.empty() && nRecurseDepth < 0; - dir->m_osFilesystem = osFilesystem; - dir->m_osObjectKey = osObjectKey; + dir->m_osFilesystem = std::move(osFilesystem); + dir->m_osObjectKey = std::move(osObjectKey); dir->m_nMaxFiles = atoi(CSLFetchNameValueDef(papszOptions, "MAXFILES", "0")); dir->m_bCacheEntries = diff --git a/port/cpl_vsil_az.cpp b/port/cpl_vsil_az.cpp index fa25c27ab833..0bd5f4176c6b 100644 --- a/port/cpl_vsil_az.cpp +++ b/port/cpl_vsil_az.cpp @@ -2541,8 +2541,8 @@ VSIDIR *VSIAzureFSHandler::OpenDir(const char *pszPath, int nRecurseDepth, dir->nRecurseDepth = nRecurseDepth; dir->poFS = this; dir->poHandleHelper = std::move(poHandleHelper); - dir->osBucket = osBucket; - dir->osObjectKey = osObjectKey; + dir->osBucket = std::move(osBucket); + dir->osObjectKey = std::move(osObjectKey); dir->nMaxFiles = atoi(CSLFetchNameValueDef(papszOptions, "MAXFILES", "0")); dir->bCacheEntries = CPLTestBool(CSLFetchNameValueDef(papszOptions, "CACHE_ENTRIES", "YES")); diff --git a/port/cpl_vsil_crypt.cpp b/port/cpl_vsil_crypt.cpp index f349ad731037..fc0cbdd1b0fa 100644 --- a/port/cpl_vsil_crypt.cpp +++ b/port/cpl_vsil_crypt.cpp @@ -1731,6 +1731,7 @@ VSICryptFilesystemHandler::Open(const char *pszFilename, const char *pszAccess, VSICryptFileHeader *poHeader = new VSICryptFileHeader(); poHeader->osIV = osIV; + CPL_IGNORE_RET_VAL(osIV); poHeader->eAlg = eAlg; poHeader->eMode = eMode; poHeader->nSectorSize = static_cast(nSectorSize); diff --git a/port/cpl_vsil_curl.cpp b/port/cpl_vsil_curl.cpp index 1ba293cb618b..68377534ae76 100644 --- a/port/cpl_vsil_curl.cpp +++ b/port/cpl_vsil_curl.cpp @@ -2092,7 +2092,7 @@ void VSICurlHandle::UpdateRedirectInfo( // figure out the expiration timestamp in local time. oFileProp.bS3LikeRedirect = true; oFileProp.nExpireTimestampLocal = time(nullptr) + nValidity; - oFileProp.osRedirectURL = osEffectiveURL; + oFileProp.osRedirectURL = std::move(osEffectiveURL); poFS->SetCachedFileProp(m_pszURL, oFileProp); } } @@ -2584,7 +2584,7 @@ int VSICurlHandle::ReadMultiRangeSingleGet(int const nRanges, if (nMergedRanges == 1) osFirstRange = osCurRange; - osLastRange = osCurRange; + osLastRange = std::move(osCurRange); } const char *pszMaxRanges = diff --git a/port/cpl_vsil_gzip.cpp b/port/cpl_vsil_gzip.cpp index 780b9eb5d86f..ef60643196c0 100644 --- a/port/cpl_vsil_gzip.cpp +++ b/port/cpl_vsil_gzip.cpp @@ -4076,7 +4076,7 @@ bool VSIZipFilesystemHandler::GetFileInfo(const char *pszFilename, memcpy(&osVal[0], &abyExtra[nPos + nPos2], nValLen); nPos2 += nValLen; - info.oMapProperties[osKey] = osVal; + info.oMapProperties[osKey] = std::move(osVal); } } } diff --git a/port/cpl_vsil_s3.cpp b/port/cpl_vsil_s3.cpp index 5bbb4504d1a7..6dcad54ff3d1 100644 --- a/port/cpl_vsil_s3.cpp +++ b/port/cpl_vsil_s3.cpp @@ -3577,8 +3577,8 @@ VSIDIR *IVSIS3LikeFSHandler::OpenDir(const char *pszPath, int nRecurseDepth, dir->nRecurseDepth = nRecurseDepth; dir->poFS = this; dir->poS3HandleHelper = poS3HandleHelper; - dir->osBucket = osBucket; - dir->osObjectKey = osObjectKey; + dir->osBucket = std::move(osBucket); + dir->osObjectKey = std::move(osObjectKey); dir->nMaxFiles = atoi(CSLFetchNameValueDef(papszOptions, "MAXFILES", "0")); dir->bCacheEntries = CPLTestBool( CSLFetchNameValueDef(papszOptions, "CACHE_ENTRIES", "TRUE")); @@ -4235,7 +4235,7 @@ bool IVSIS3LikeFSHandler::Sync(const char *pszSource, const char *pszTarget, if (CanSkipUploadFromLocalToNetwork( fpIn, osSubSource.c_str(), osSubTarget.c_str(), chunk.nMTime, oIterExistingTarget->second.nMTime, - [&oIterExistingTarget](const char *) + [&oIterExistingTarget](const char *) -> std::string { return std::string(CSLFetchNameValueDef( oIterExistingTarget->second.papszExtra, @@ -4429,7 +4429,7 @@ bool IVSIS3LikeFSHandler::Sync(const char *pszSource, const char *pszTarget, if (CanSkipUploadFromLocalToNetwork( fpIn, osSourceWithoutSlash.c_str(), osTarget.c_str(), sSource.st_mtime, sTarget.st_mtime, - [this](const char *pszFilename) + [this](const char *pszFilename) -> std::string { FileProp cachedFileProp; if (GetCachedFileProp( @@ -4509,7 +4509,7 @@ bool IVSIS3LikeFSHandler::Sync(const char *pszSource, const char *pszTarget, def.nExpectedCount = static_cast( (chunk.nTotalSize + chunk.nSize - 1) / chunk.nSize); def.nTotalSize = chunk.nTotalSize; - oMapMultiPartDefs[osTarget] = def; + oMapMultiPartDefs[osTarget] = std::move(def); } else { diff --git a/port/cplstring.cpp b/port/cplstring.cpp index 351625318a2f..7c4223dbbbe8 100644 --- a/port/cplstring.cpp +++ b/port/cplstring.cpp @@ -446,16 +446,15 @@ CPLString CPLURLGetValue(const char *pszURL, const char *pszKey) CPLString CPLURLAddKVP(const char *pszURL, const char *pszKey, const char *pszValue) { - CPLString osURL(pszURL); - if (strchr(osURL, '?') == nullptr) - osURL += "?"; - pszURL = osURL.c_str(); + const CPLString osURL(strchr(pszURL, '?') == nullptr + ? CPLString(pszURL).append("?") + : pszURL); CPLString osKey(pszKey); osKey += "="; size_t nKeyPos = osURL.ifind(osKey); if (nKeyPos != std::string::npos && nKeyPos > 0 && - (pszURL[nKeyPos - 1] == '?' || pszURL[nKeyPos - 1] == '&')) + (osURL[nKeyPos - 1] == '?' || osURL[nKeyPos - 1] == '&')) { CPLString osNewURL(osURL); osNewURL.resize(nKeyPos); @@ -464,7 +463,7 @@ CPLString CPLURLAddKVP(const char *pszURL, const char *pszKey, osNewURL += osKey; osNewURL += pszValue; } - const char *pszNext = strchr(pszURL + nKeyPos, '&'); + const char *pszNext = strchr(osURL.c_str() + nKeyPos, '&'); if (pszNext) { if (osNewURL.back() == '&' || osNewURL.back() == '?') @@ -476,14 +475,15 @@ CPLString CPLURLAddKVP(const char *pszURL, const char *pszKey, } else { + CPLString osNewURL(osURL); if (pszValue) { - if (osURL.back() != '&' && osURL.back() != '?') - osURL += '&'; - osURL += osKey; - osURL += pszValue; + if (osNewURL.back() != '&' && osNewURL.back() != '?') + osNewURL += '&'; + osNewURL += osKey; + osNewURL += pszValue; } - return osURL; + return osNewURL; } }