From 05ea86d7ca2a7c28e990243bd850fcd1c171cf2d Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Sun, 14 Jan 2024 19:53:49 +0100 Subject: [PATCH 1/3] VSICurlFilesystemHandlerBase::ReadDirInternal(): avoid false positive Coverity warning about use after free --- port/cpl_vsil_curl.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/port/cpl_vsil_curl.cpp b/port/cpl_vsil_curl.cpp index 6982297e5a20..da802d5be6d9 100644 --- a/port/cpl_vsil_curl.cpp +++ b/port/cpl_vsil_curl.cpp @@ -5149,15 +5149,16 @@ char **VSICurlFilesystemHandlerBase::ReadDirInternal(const char *pszDirname, { std::string osDirname(pszDirname); - const char *pszUpDir = strstr(osDirname.c_str(), "/.."); - if (pszUpDir != nullptr) + // Replace a/b/../c by a/c + const auto posSlashDotDot = osDirname.find("/.."); + if (posSlashDotDot != std::string::npos && posSlashDotDot >= 1) { - int pos = static_cast(pszUpDir - osDirname.c_str() - 1); - while (pos >= 0 && osDirname[pos] != '/') - pos--; - if (pos >= 1) + const auto posPrecedingSlash = + osDirname.find_last_of('/', posSlashDotDot - 1); + if (posPrecedingSlash != std::string::npos && posPrecedingSlash >= 1) { - osDirname = osDirname.substr(0, pos) + std::string(pszUpDir + 3); + osDirname.erase(osDirname.begin() + posPrecedingSlash, + osDirname.begin() + posSlashDotDot + strlen("/..")); } } From ca1e76438d9d99c08daf27e95ef2168f17c94329 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Sun, 14 Jan 2024 19:54:54 +0100 Subject: [PATCH 2/3] Internal libjson: silence 'toctou' --- ogr/ogrsf_frmts/geojson/libjson/random_seed.c | 1 + 1 file changed, 1 insertion(+) diff --git a/ogr/ogrsf_frmts/geojson/libjson/random_seed.c b/ogr/ogrsf_frmts/geojson/libjson/random_seed.c index 9bf80403d117..9fa2730a5de9 100644 --- a/ogr/ogrsf_frmts/geojson/libjson/random_seed.c +++ b/ogr/ogrsf_frmts/geojson/libjson/random_seed.c @@ -229,6 +229,7 @@ static int get_dev_random_seed(int *seed) if ((buf.st_mode & S_IFCHR) == 0) return -1; + /* coverity[toctou] */ int fd = open(dev_random_file, O_RDONLY); if (fd < 0) { From db6225e661d52985e6b3b3fc33f8363e25231b16 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Sun, 14 Jan 2024 22:47:38 +0100 Subject: [PATCH 3/3] Avoid/fix Coverity performance warnings --- apps/gdalmdiminfo_lib.cpp | 4 +- apps/gdalmdimtranslate_lib.cpp | 18 +++-- apps/ogr2ogr_lib.cpp | 6 +- autotest/cpp/test_cpl.cpp | 1 + autotest/cpp/test_ogr.cpp | 2 + autotest/cpp/test_ogr_organize_polygons.cpp | 22 +++--- frmts/adrg/adrgdataset.cpp | 2 +- frmts/adrg/srpdataset.cpp | 2 +- frmts/aigrid/aigdataset.cpp | 17 ++-- frmts/dimap/dimapdataset.cpp | 32 ++++---- frmts/eeda/eedacommon.cpp | 4 +- frmts/ers/ersdataset.cpp | 2 +- frmts/fits/fitsdataset.cpp | 4 +- frmts/gtiff/gt_citation.cpp | 2 +- frmts/gtiff/gt_wkt_srs.cpp | 2 +- frmts/gtiff/gtiffrasterband_write.cpp | 2 +- frmts/hdf4/hdf4multidim.cpp | 2 +- frmts/hdf5/bagdataset.cpp | 5 +- frmts/hdf5/hdf5eosparser.cpp | 12 +-- frmts/hdf5/hdf5multidim.cpp | 5 +- frmts/hf2/hf2dataset.cpp | 2 +- frmts/hfa/hfadataset.cpp | 4 +- frmts/hfa/hfaopen.cpp | 4 +- frmts/ilwis/ilwisdataset.cpp | 4 +- frmts/jpegxl/jpegxl.cpp | 2 +- .../kmlsuperoverlaydataset.cpp | 8 +- frmts/netcdf/netcdfdataset.cpp | 2 +- frmts/netcdf/netcdfmultidim.cpp | 4 +- frmts/nitf/ecrgtocdataset.cpp | 12 ++- frmts/ogcapi/gdalogcapidataset.cpp | 5 +- frmts/pcidsk/sdk/core/cpcidskfile.cpp | 2 +- frmts/pcidsk/sdk/core/cpcidskfile.h | 2 +- frmts/pcidsk/sdk/core/pcidsk_utils.cpp | 6 +- frmts/pcidsk/sdk/core/pcidskcreate.cpp | 2 +- frmts/pcidsk/sdk/pcidsk_file.h | 2 +- .../pcidsk/sdk/segment/metadatasegment_p.cpp | 2 +- frmts/pdf/pdfdataset.cpp | 20 +++-- frmts/pdf/pdfobject.cpp | 2 +- frmts/pdf/pdfreadvectors.cpp | 10 +-- frmts/pds/isis2dataset.cpp | 31 ++++---- frmts/pds/isis3dataset.cpp | 12 +-- frmts/pds/pds4dataset.cpp | 6 +- frmts/pds/pdsdataset.cpp | 2 +- frmts/pds/vicardataset.cpp | 2 +- frmts/postgisraster/postgisrasterdataset.cpp | 13 +-- frmts/raw/btdataset.cpp | 2 +- frmts/raw/envidataset.cpp | 12 +-- frmts/raw/rrasterdataset.cpp | 49 +++++------- frmts/stacit/stacitdataset.cpp | 4 +- frmts/tga/tgadataset.cpp | 3 +- frmts/tiledb/tiledbmultidimarray.cpp | 11 +-- frmts/tiledb/tiledbmultidimgroup.cpp | 2 +- frmts/vrt/vrtmultidim.cpp | 4 +- frmts/wcs/wcsdataset.cpp | 9 +-- frmts/wcs/wcsdataset110.cpp | 79 +++++++------------ frmts/wcs/wcsdataset201.cpp | 5 -- frmts/wcs/wcsutils.cpp | 2 +- frmts/zarr/zarr_group.cpp | 2 +- frmts/zarr/zarr_v2_array.cpp | 2 +- frmts/zarr/zarrdriver.cpp | 4 +- gcore/gdal_mdreader.cpp | 2 +- gcore/gdal_rat.cpp | 2 +- gcore/gdaljp2structure.cpp | 4 +- gcore/gdalmultidim.cpp | 7 +- gcore/gdalmultidim_gridded.cpp | 2 +- gcore/gdalopeninfo.cpp | 2 +- gcore/gdalpythondriverloader.cpp | 2 +- gcore/mdreader/reader_alos.cpp | 20 ++--- gcore/mdreader/reader_geo_eye.cpp | 12 +-- gcore/mdreader/reader_rapid_eye.cpp | 6 +- gnm/gnm_frmts/db/gnmdbnetwork.cpp | 2 +- ogr/ogr_geocoding.cpp | 5 +- ogr/ogr_xerces.cpp | 2 +- ogr/ogrcurve.cpp | 2 +- ogr/ogrsf_frmts/arrow/ogrfeatherlayer.cpp | 2 +- .../arrow_common/ograrrowwriterlayer.hpp | 3 +- ogr/ogrsf_frmts/dxf/ogrdxflayer.cpp | 4 +- ogr/ogrsf_frmts/dxf/ogrdxfwriterlayer.cpp | 2 +- .../edigeo/ogredigeodatasource.cpp | 2 +- .../elastic/ogrelasticaggregationlayer.cpp | 2 +- ogr/ogrsf_frmts/filegdb/FGdbDatasource.cpp | 8 +- ogr/ogrsf_frmts/flatgeobuf/packedrtree.cpp | 13 +-- ogr/ogrsf_frmts/flatgeobuf/packedrtree.h | 2 +- .../geojson/directedacyclicgraph.hpp | 2 +- ogr/ogrsf_frmts/gmlas/ogrgmlaslayer.cpp | 2 +- .../gmlas/ogrgmlasschemaanalyzer.cpp | 8 +- ogr/ogrsf_frmts/gmt/ogrgmtlayer.cpp | 10 +-- .../gpkg/ogrgeopackagedatasource.cpp | 13 +-- .../gpkg/ogrgeopackagetablelayer.cpp | 2 +- ogr/ogrsf_frmts/hana/ogrhanadatasource.cpp | 14 ++-- ogr/ogrsf_frmts/hana/ogrhanafeaturereader.cpp | 2 +- ogr/ogrsf_frmts/jsonfg/ogrjsonfgreader.cpp | 2 +- .../libkml/ogrlibkmldatasource.cpp | 12 +-- ogr/ogrsf_frmts/libkml/ogrlibkmlstyle.cpp | 2 +- ogr/ogrsf_frmts/mvt/ogrmvtdataset.cpp | 15 ++-- ogr/ogrsf_frmts/ngw/ngw_api.cpp | 2 +- ogr/ogrsf_frmts/ngw/ogrngwdriver.cpp | 2 +- ogr/ogrsf_frmts/ngw/ogrngwlayer.cpp | 10 +-- ogr/ogrsf_frmts/ogdi/ogrogdidatasource.cpp | 1 + .../ogropenfilegdbdatasource_write.cpp | 4 +- ogr/ogrsf_frmts/osm/ogrosmlayer.cpp | 4 +- ogr/ogrsf_frmts/parquet/ogrparquetdriver.cpp | 16 ++-- ogr/ogrsf_frmts/pgeo/ogrpgeodatasource.cpp | 3 +- .../plscenes/ogrplscenesdatav1dataset.cpp | 2 +- .../sqlite/ogrsqlitedatasource.cpp | 2 +- .../sqlite/ogrsqliteexecutesql.cpp | 4 +- ogr/ogrsf_frmts/wfs/ogr_wfs.h | 2 +- ogr/ogrsf_frmts/wfs/ogroapifdriver.cpp | 8 +- ogr/ogrsf_frmts/wfs/ogrwfslayer.cpp | 2 +- port/cpl_aws.cpp | 34 ++++---- port/cpl_azure.cpp | 2 +- port/cpl_google_cloud.cpp | 4 +- port/cpl_odbc.cpp | 2 +- port/cpl_swift.cpp | 12 +-- port/cpl_vsil_adls.cpp | 4 +- port/cpl_vsil_az.cpp | 2 +- port/cpl_vsil_curl.cpp | 2 +- port/cpl_vsil_s3.cpp | 9 ++- port/cpl_xml_validate.cpp | 8 +- 119 files changed, 413 insertions(+), 417 deletions(-) diff --git a/apps/gdalmdiminfo_lib.cpp b/apps/gdalmdiminfo_lib.cpp index e15d7c9c4845..386ba525cf02 100644 --- a/apps/gdalmdiminfo_lib.cpp +++ b/apps/gdalmdiminfo_lib.cpp @@ -757,7 +757,7 @@ static void DumpArray(const std::shared_ptr &rootGroup, } serializer.AddObjKey("datatype"); - const auto dt(array->GetDataType()); + const auto &dt(array->GetDataType()); DumpDataType(dt, serializer); auto dims = array->GetDimensions(); @@ -1128,7 +1128,7 @@ char *GDALMultiDimInfo(GDALDatasetH hDataset, "Cannot find group %s", aosTokens[i]); return nullptr; } - curGroup = curGroupNew; + curGroup = std::move(curGroupNew); } const char *pszArrayName = aosTokens[aosTokens.size() - 1]; auto array(curGroup->OpenMDArray(pszArrayName)); diff --git a/apps/gdalmdimtranslate_lib.cpp b/apps/gdalmdimtranslate_lib.cpp index c7257e1a011e..cc9c84d959ec 100644 --- a/apps/gdalmdimtranslate_lib.cpp +++ b/apps/gdalmdimtranslate_lib.cpp @@ -424,8 +424,9 @@ GetDimensionDesc(DimensionRemapper &oDimRemapper, const bool bIsNumeric = var->GetDataType().GetClass() == GEDTC_NUMERIC; - const auto dt(bIsNumeric ? GDALExtendedDataType::Create(GDT_Float64) - : GDALExtendedDataType::CreateString()); + const GDALExtendedDataType dt( + bIsNumeric ? GDALExtendedDataType::Create(GDT_Float64) + : GDALExtendedDataType::CreateString()); double dfMin = 0; double dfMax = 0; @@ -1158,7 +1159,7 @@ static bool TranslateArray( dt.FreeDynamicMemory(&abyTmp[0]); } - const auto unit(srcIndexVar->GetUnit()); + const auto &unit(srcIndexVar->GetUnit()); if (!unit.empty()) { auto dstAttr = dstArray->CreateAttribute( @@ -1197,9 +1198,11 @@ static bool TranslateArray( band < 0 ? srcArray->GetFullName() : std::string(), band >= 1 ? CPLSPrintf("%d", band) : std::string(), std::move(anTransposedAxis), - bResampled ? (viewExpr.empty() ? std::string("resample=true") - : "resample=true," + viewExpr) - : viewExpr, + bResampled + ? (viewExpr.empty() ? std::string("resample=true") + : std::string("resample=true,") + .append(std::move(viewExpr))) + : std::move(viewExpr), std::move(anSrcOffset), std::move(anCount), std::move(anStep), std::move(anDstOffset))); dstArrayVRT->AddSource(std::move(poSource)); @@ -1316,7 +1319,8 @@ static bool CopyGroup( { CPLErrorHandlerPusher oHandlerPusher(CPLQuietErrorHandler); CPLErrorStateBackuper oErrorStateBackuper; - oCorrespondingDimIter->second->SetIndexingVariable(dstArray); + oCorrespondingDimIter->second->SetIndexingVariable( + std::move(dstArray)); } } } diff --git a/apps/ogr2ogr_lib.cpp b/apps/ogr2ogr_lib.cpp index edacb43c5eec..e280f5cc89f8 100644 --- a/apps/ogr2ogr_lib.cpp +++ b/apps/ogr2ogr_lib.cpp @@ -3905,8 +3905,8 @@ bool SetupTargetLayer::CanUseWriteArrowBatch( const auto poSrcFieldDefn = poSrcFDefn->GetFieldDefn(iSrcField); // Create field domain in output dataset if not already existing. - const auto osDomainName = - poSrcFieldDefn->GetDomainName(); + const std::string osDomainName( + poSrcFieldDefn->GetDomainName()); if (!osDomainName.empty()) { if (m_poDstDS->TestCapability( @@ -4921,7 +4921,7 @@ SetupTargetLayer::Setup(OGRLayer *poSrcLayer, const char *pszNewLayerName, } // Create field domain in output dataset if not already existing. - const auto osDomainName = oFieldDefn.GetDomainName(); + const std::string osDomainName(oFieldDefn.GetDomainName()); if (!osDomainName.empty()) { if (m_poDstDS->TestCapability(ODsCAddFieldDomain) && diff --git a/autotest/cpp/test_cpl.cpp b/autotest/cpp/test_cpl.cpp index b3749fa8b8de..047a1b774cb9 100644 --- a/autotest/cpp/test_cpl.cpp +++ b/autotest/cpp/test_cpl.cpp @@ -648,6 +648,7 @@ TEST_F(test_cpl, CPLStringList_NameValue) { CPLStringList oTemp; oTemp.AddString("test"); + // coverity[copy_assignment_call] oCopy = oTemp; } EXPECT_STREQ(oCopy[0], "test"); diff --git a/autotest/cpp/test_ogr.cpp b/autotest/cpp/test_ogr.cpp index effb932ce53d..448b40b41aa6 100644 --- a/autotest/cpp/test_ogr.cpp +++ b/autotest/cpp/test_ogr.cpp @@ -1442,6 +1442,7 @@ TEST_F(test_ogr, DatasetFeature_and_LayerFeature_iterators) { GDALDataset::Layers::Iterator srcIter(poDS->GetLayers().begin()); ++srcIter; + // coverity[copy_constructor_call] GDALDataset::Layers::Iterator newIter(srcIter); ASSERT_EQ(*newIter, layers[1]); } @@ -1451,6 +1452,7 @@ TEST_F(test_ogr, DatasetFeature_and_LayerFeature_iterators) GDALDataset::Layers::Iterator srcIter(poDS->GetLayers().begin()); ++srcIter; GDALDataset::Layers::Iterator newIter; + // coverity[copy_assignent_call] newIter = srcIter; ASSERT_EQ(*newIter, layers[1]); } diff --git a/autotest/cpp/test_ogr_organize_polygons.cpp b/autotest/cpp/test_ogr_organize_polygons.cpp index f87fd23b6c71..eaba36bd9b28 100644 --- a/autotest/cpp/test_ogr_organize_polygons.cpp +++ b/autotest/cpp/test_ogr_organize_polygons.cpp @@ -72,7 +72,7 @@ TEST_P(OrganizePolygonsTest, EmptyInputVector) { std::vector polygons; - auto method = GetParam(); + const auto &method = GetParam(); auto result = organizePolygons(polygons, method); ASSERT_NE(result, nullptr); @@ -87,7 +87,7 @@ TEST_P(OrganizePolygonsTest, SinglePolygonInput) std::unique_ptr expected(polygons.front()->clone()); - auto method = GetParam(); + const auto &method = GetParam(); auto result = organizePolygons(polygons, method); ASSERT_NE(result, nullptr); @@ -102,7 +102,7 @@ TEST_P(OrganizePolygonsTest, SingleCurvePolygonInput) std::unique_ptr expected(polygons.front()->clone()); - auto method = GetParam(); + const auto &method = GetParam(); auto result = organizePolygons(polygons, method); ASSERT_NE(result, nullptr); @@ -115,7 +115,7 @@ TEST_P(OrganizePolygonsTest, SinglePointInput) std::vector polygons; polygons.push_back(readWKT("POINT (0 0)")); - auto method = GetParam(); + const auto &method = GetParam(); auto result = organizePolygons(polygons, method); ASSERT_NE(result, nullptr); @@ -130,7 +130,7 @@ TEST_P(OrganizePolygonsTest, MixedPolygonCurvePolygonInput) readWKT("POLYGON ((10 10, 20 10, 20 20, 20 10, 10 10))")); polygons.push_back(readWKT("CURVEPOLYGON ((0 0, 1 0, 1 1, 0 0))")); - auto method = GetParam(); + const auto &method = GetParam(); auto result = organizePolygons(polygons, method); ASSERT_NE(result, nullptr); @@ -152,7 +152,7 @@ TEST_P(OrganizePolygonsTest, MixedPolygonPointInput) std::unique_ptr expected(polygons[0]->clone()); - auto method = GetParam(); + const auto &method = GetParam(); auto result = organizePolygons(polygons, method); ASSERT_NE(result, nullptr); @@ -165,7 +165,7 @@ TEST_P(OrganizePolygonsTest, CWPolygonCCWHole) polygons.push_back(readWKT("POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))")); polygons.push_back(readWKT("POLYGON ((1 1, 2 1, 2 2, 1 2, 1 1))")); - auto method = GetParam(); + const auto &method = GetParam(); auto result = organizePolygons(polygons, method); ASSERT_NE(result, nullptr); @@ -195,7 +195,7 @@ TEST_P(OrganizePolygonsTest, CWPolygonCCWLakeCWIslandInLake) polygons.push_back( readWKT("POLYGON ((15 15, 15 16, 16 16, 16 15, 15 15))")); // CW - auto method = GetParam(); + const auto &method = GetParam(); auto result = organizePolygons(polygons, method); ASSERT_NE(result, nullptr); @@ -217,7 +217,7 @@ TEST_P(OrganizePolygonsTest, AdjacentCCWPolygons) polygons.push_back(readWKT("POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))")); // CCW polygons.push_back(readWKT("POLYGON ((1 0, 2 0, 2 1, 1 1, 1 0))")); // CCW - auto method = GetParam(); + const auto &method = GetParam(); auto result = organizePolygons(polygons, method); ASSERT_NE(result, nullptr); @@ -236,7 +236,7 @@ TEST_P(OrganizePolygonsTest, HoleAlongEdge) readWKT("POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))")); // CW polygons.push_back(readWKT("POLYGON ((0 2, 1 2, 1 3, 0 3, 0 2))")); // CCW - auto method = GetParam(); + const auto &method = GetParam(); auto result = organizePolygons(polygons, method); ASSERT_NE(result, nullptr); @@ -257,7 +257,7 @@ TEST_P(OrganizePolygonsTest, CrossingCCWPolygons) polygons.push_back(readWKT("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))")); polygons.push_back(readWKT("POLYGON ((5 5, 15 5, 15 15, 5 15, 5 5))")); - auto method = GetParam(); + const auto &method = GetParam(); auto result = organizePolygons(polygons, method); ASSERT_NE(result, nullptr); diff --git a/frmts/adrg/adrgdataset.cpp b/frmts/adrg/adrgdataset.cpp index c773bf83139a..bb2935dd5b55 100644 --- a/frmts/adrg/adrgdataset.cpp +++ b/frmts/adrg/adrgdataset.cpp @@ -1779,7 +1779,7 @@ GDALDataset *ADRGDataset::Create(const char *pszFilename, int nXSize, poDS->fdIMG = fdIMG; poDS->fdTHF = fdTHF; - poDS->osBaseFileName = osBaseFileName; + poDS->osBaseFileName = std::move(osBaseFileName); poDS->bCreation = TRUE; poDS->nNextAvailableBlock = 1; poDS->NFC = (nXSize + 127) / 128; diff --git a/frmts/adrg/srpdataset.cpp b/frmts/adrg/srpdataset.cpp index 499838935955..8c8295b6e804 100644 --- a/frmts/adrg/srpdataset.cpp +++ b/frmts/adrg/srpdataset.cpp @@ -1617,7 +1617,7 @@ GDALDataset *SRPDataset::Open(GDALOpenInfo *poOpenInfo) return nullptr; } - osGENFileName = osFileName; + osGENFileName = std::move(osFileName); } } diff --git a/frmts/aigrid/aigdataset.cpp b/frmts/aigrid/aigdataset.cpp index f46974a7fc25..ede0a42e16ac 100644 --- a/frmts/aigrid/aigdataset.cpp +++ b/frmts/aigrid/aigdataset.cpp @@ -689,19 +689,20 @@ GDALDataset *AIGDataset::Open(GDALOpenInfo *poOpenInfo) // Look in parent if we don't find a .clr in the coverage dir. if (osClrFilename.empty()) { - osTestName.Printf("%s/../%s.clr", psInfo->pszCoverName, - CPLGetFilename(osCleanPath)); + CPLString osTestClrFilename; + osTestClrFilename.Printf("%s/../%s.clr", psInfo->pszCoverName, + CPLGetFilename(osCleanPath)); - if (VSIStatL(osTestName, &sStatBuf) != 0) + if (VSIStatL(osTestClrFilename, &sStatBuf) != 0) { - osTestName.Printf("%s/../%s.CLR", psInfo->pszCoverName, - CPLGetFilename(osCleanPath)); + osTestClrFilename.Printf("%s/../%s.CLR", psInfo->pszCoverName, + CPLGetFilename(osCleanPath)); - if (!VSIStatL(osTestName, &sStatBuf)) - osClrFilename = osTestName; + if (!VSIStatL(osTestClrFilename, &sStatBuf)) + osClrFilename = std::move(osTestClrFilename); } else - osClrFilename = osTestName; + osClrFilename = std::move(osTestClrFilename); } if (!osClrFilename.empty()) diff --git a/frmts/dimap/dimapdataset.cpp b/frmts/dimap/dimapdataset.cpp index 6a2f5e5f7d6d..3247eb952d20 100644 --- a/frmts/dimap/dimapdataset.cpp +++ b/frmts/dimap/dimapdataset.cpp @@ -554,17 +554,17 @@ GDALDataset *DIMAPDataset::Open(GDALOpenInfo *poOpenInfo) } VSIStatBufL sStat; - CPLString osMDFilename(osFilename); + std::string osMDFilename(osFilename); if (VSIStatL(osFilename.c_str(), &sStat) == 0 && VSI_ISDIR(sStat.st_mode)) { osMDFilename = CPLFormCIFilename(osFilename, "METADATA.DIM", nullptr); /* DIMAP2 */ - if (VSIStatL(osMDFilename, &sStat) != 0) + if (VSIStatL(osMDFilename.c_str(), &sStat) != 0) { osMDFilename = CPLFormCIFilename(osFilename, "VOL_PHR.XML", nullptr); - if (VSIStatL(osMDFilename, &sStat) != 0) + if (VSIStatL(osMDFilename.c_str(), &sStat) != 0) { // DIMAP VHR2020 file. osMDFilename = @@ -576,7 +576,7 @@ GDALDataset *DIMAPDataset::Open(GDALOpenInfo *poOpenInfo) /* -------------------------------------------------------------------- */ /* Ingest the xml file. */ /* -------------------------------------------------------------------- */ - CPLXMLNode *psProduct = CPLParseXMLFile(osMDFilename); + CPLXMLNode *psProduct = CPLParseXMLFile(osMDFilename.c_str()); if (psProduct == nullptr) return nullptr; @@ -592,9 +592,9 @@ GDALDataset *DIMAPDataset::Open(GDALOpenInfo *poOpenInfo) const int nProductVersion = dfMetadataFormatVersion >= 2.0 ? 2 : 1; - CPLString osImageDSFilename; - CPLString osDIMAPFilename; - CPLString osRPCFilename; + std::string osImageDSFilename; + std::string osDIMAPFilename; + std::string osRPCFilename; CPLXMLNode *psProductDim = nullptr; CPLXMLNode *psProductStrip = nullptr; @@ -662,7 +662,7 @@ GDALDataset *DIMAPDataset::Open(GDALOpenInfo *poOpenInfo) } else { - CPLString osPath = CPLGetPath(osMDFilename); + CPLString osPath = CPLGetPath(osMDFilename.c_str()); osDIMAPFilename = CPLFormFilename(osPath, pszHref, nullptr); } @@ -674,7 +674,7 @@ GDALDataset *DIMAPDataset::Open(GDALOpenInfo *poOpenInfo) if (strlen(pszDataFileHref) > 0) { - CPLString osPath = CPLGetPath(osMDFilename); + CPLString osPath = CPLGetPath(osMDFilename.c_str()); osImageDSFilename = CPLFormFilename( osPath, pszDataFileHref, nullptr); } @@ -692,7 +692,7 @@ GDALDataset *DIMAPDataset::Open(GDALOpenInfo *poOpenInfo) } } - psProductDim = CPLParseXMLFile(osDIMAPFilename); + psProductDim = CPLParseXMLFile(osDIMAPFilename.c_str()); if (psProductDim == nullptr) { CPLDestroyXMLNode(psProduct); @@ -724,7 +724,7 @@ GDALDataset *DIMAPDataset::Open(GDALOpenInfo *poOpenInfo) if (strlen(pszHref) > 0) // STRIP product found. { - CPLString osPath = CPLGetPath(osDIMAPFilename); + CPLString osPath = CPLGetPath(osDIMAPFilename.c_str()); osSTRIPFilename = CPLFormCIFilename(osPath, pszHref, nullptr); if (VSIStatL(osSTRIPFilename, &sStat) == 0) @@ -755,7 +755,7 @@ GDALDataset *DIMAPDataset::Open(GDALOpenInfo *poOpenInfo) if (strlen(pszHref) > 0) // RPC product found. { - CPLString osPath = CPLGetPath(osDIMAPFilename); + CPLString osPath = CPLGetPath(osDIMAPFilename.c_str()); osRPCFilename = CPLFormCIFilename(osPath, pszHref, nullptr); @@ -778,11 +778,11 @@ GDALDataset *DIMAPDataset::Open(GDALOpenInfo *poOpenInfo) poDS->psProduct = psProduct; poDS->psProductDim = psProductDim; poDS->psProductStrip = psProductStrip; - poDS->osRPCFilename = osRPCFilename; + poDS->osRPCFilename = std::move(osRPCFilename); poDS->nProductVersion = nProductVersion; - poDS->osMDFilename = osMDFilename; - poDS->osImageDSFilename = osImageDSFilename; - poDS->osDIMAPFilename = osDIMAPFilename; + poDS->osMDFilename = std::move(osMDFilename); + poDS->osImageDSFilename = std::move(osImageDSFilename); + poDS->osDIMAPFilename = std::move(osDIMAPFilename); const int res = (nProductVersion == 2) ? poDS->ReadImageInformation2() : poDS->ReadImageInformation(); diff --git a/frmts/eeda/eedacommon.cpp b/frmts/eeda/eedacommon.cpp index cbef5165aefb..0ba2c6a82492 100644 --- a/frmts/eeda/eedacommon.cpp +++ b/frmts/eeda/eedacommon.cpp @@ -236,12 +236,12 @@ BuildBandDescArray(json_object *poBands, EEDAIBandDesc oDesc; oDesc.osName = pszBandId; - oDesc.osWKT = osWKT; + oDesc.osWKT = std::move(osWKT); oDesc.eDT = eDT; oDesc.adfGeoTransform = std::move(adfGeoTransform); oDesc.nWidth = nWidth; oDesc.nHeight = nHeight; - aoBandDesc.push_back(oDesc); + aoBandDesc.emplace_back(std::move(oDesc)); } return aoBandDesc; } diff --git a/frmts/ers/ersdataset.cpp b/frmts/ers/ersdataset.cpp index 3717dad899fe..919d64f7d4b4 100644 --- a/frmts/ers/ersdataset.cpp +++ b/frmts/ers/ersdataset.cpp @@ -1057,7 +1057,7 @@ GDALDataset *ERSDataset::Open(GDALOpenInfo *poOpenInfo) else poDS->fpImage = VSIFOpenL(osDataFilePath, "r"); - poDS->osRawFilename = osDataFilePath; + poDS->osRawFilename = std::move(osDataFilePath); if (poDS->fpImage != nullptr && nBands > 0) { diff --git a/frmts/fits/fitsdataset.cpp b/frmts/fits/fitsdataset.cpp index b2884ba06edd..01056ca4776c 100644 --- a/frmts/fits/fitsdataset.cpp +++ b/frmts/fits/fitsdataset.cpp @@ -1048,7 +1048,7 @@ void FITSLayer::RunDeferredFieldCreation(const OGRFeature *poFeature) (iBit = strtol(pszBit + strlen("_bit"), &pszEndPtr, 10)) > 0 && pszEndPtr && *pszEndPtr == '\0') { - CPLString osName; + std::string osName; osName.assign(pszFieldName, pszBit - pszFieldName); if (oSetBitFieldNames.find(osName) == oSetBitFieldNames.end()) { @@ -1060,7 +1060,7 @@ void FITSLayer::RunDeferredFieldCreation(const OGRFeature *poFeature) if (osPendingBitFieldName.empty()) { - osPendingBitFieldName = osName; + osPendingBitFieldName = std::move(osName); nPendingBitFieldSize = 1; continue; } diff --git a/frmts/gtiff/gt_citation.cpp b/frmts/gtiff/gt_citation.cpp index 8711ffd65ccc..d85cae8d82c0 100644 --- a/frmts/gtiff/gt_citation.cpp +++ b/frmts/gtiff/gt_citation.cpp @@ -472,7 +472,7 @@ void SetGeogCSCitation(GTIF *psGTIF, if (bRewriteGeogCitation) { - oMapAsciiKeys[GeogCitationGeoKey] = osCitation; + oMapAsciiKeys[GeogCitationGeoKey] = std::move(osCitation); } } diff --git a/frmts/gtiff/gt_wkt_srs.cpp b/frmts/gtiff/gt_wkt_srs.cpp index 6e31d12d9ecd..cd5b63a18e80 100644 --- a/frmts/gtiff/gt_wkt_srs.cpp +++ b/frmts/gtiff/gt_wkt_srs.cpp @@ -1324,7 +1324,7 @@ OGRSpatialReferenceH GTIFGetOGISDefnAsOSR(GTIF *hGTIF, GTIFDefn *psDefn) oSRSTmp.CopyGeogCSFrom(&oSRS); oSRSTmp.UpdateCoordinateSystemFromGeogCRS(); } - oSRS = oSRSTmp; + oSRS = std::move(oSRSTmp); } } diff --git a/frmts/gtiff/gtiffrasterband_write.cpp b/frmts/gtiff/gtiffrasterband_write.cpp index a1a5e36b9366..de8d09e6934e 100644 --- a/frmts/gtiff/gtiffrasterband_write.cpp +++ b/frmts/gtiff/gtiffrasterband_write.cpp @@ -273,7 +273,7 @@ CPLErr GTiffRasterBand::SetUnitType(const char *pszNewValue) if (osNewValue.compare(m_osUnitType) != 0) m_poGDS->m_bMetadataChanged = true; - m_osUnitType = osNewValue; + m_osUnitType = std::move(osNewValue); return CE_None; } diff --git a/frmts/hdf4/hdf4multidim.cpp b/frmts/hdf4/hdf4multidim.cpp index 1519817ddbcc..e1c84535ef5e 100644 --- a/frmts/hdf4/hdf4multidim.cpp +++ b/frmts/hdf4/hdf4multidim.cpp @@ -2644,7 +2644,7 @@ HDF4SDSGroup::GetDimensions(CSLConstList) const if (poArray) { m_oSetIndexingVariables.push_back(poArray); - poDim->SetIndexingVariable(poArray); + poDim->SetIndexingVariable(std::move(poArray)); } } diff --git a/frmts/hdf5/bagdataset.cpp b/frmts/hdf5/bagdataset.cpp index c5b4a9529475..4f19af44b6ef 100644 --- a/frmts/hdf5/bagdataset.cpp +++ b/frmts/hdf5/bagdataset.cpp @@ -3440,8 +3440,7 @@ bool BAGDataset::OpenRaster(GDALOpenInfo *poOpenInfo, osGeorefMetadataLayer.c_str()); 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", @@ -4863,7 +4862,7 @@ OGRErr BAGDataset::ParseWKTFromXML(const char *pszISOXML) &m_oSRS, &oVertCRS); oCompoundCRS.SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER); - m_oSRS = oCompoundCRS; + m_oSRS = std::move(oCompoundCRS); } CPLFree(pszVertCRSWKT); diff --git a/frmts/hdf5/hdf5eosparser.cpp b/frmts/hdf5/hdf5eosparser.cpp index 72ae6c393162..f833cd950aad 100644 --- a/frmts/hdf5/hdf5eosparser.cpp +++ b/frmts/hdf5/hdf5eosparser.cpp @@ -353,9 +353,9 @@ void HDF5EOSParser::ParseSwathStructure(const CPLJSONObject &oSwathStructure) int nSize = oDimension.GetInteger("Size"); oMapDimensionNameToSize[osDimensionName] = nSize; Dimension oDim; - oDim.osName = osDimensionName; + oDim.osName = std::move(osDimensionName); oDim.nSize = nSize; - poSwathMetadata->aoDimensions.push_back(oDim); + poSwathMetadata->aoDimensions.emplace_back(std::move(oDim)); } } @@ -439,18 +439,19 @@ void HDF5EOSParser::ParseSwathStructure(const CPLJSONObject &oSwathStructure) { SwathGeolocationFieldMetadata oMetadata; oMetadata.poSwathMetadata = poSwathMetadataRef; - oMetadata.aoDimensions = aoDimensions; if (osGeoFieldName == "Longitude") aoLongitudeDimensions = aoDimensions; else if (osGeoFieldName == "Latitude") aoLatitudeDimensions = aoDimensions; + oMetadata.aoDimensions = std::move(aoDimensions); + const std::string osSubdatasetName = "//HDFEOS/SWATHS/" + osSwathName + "/Geolocation_Fields/" + osGeoFieldName; m_oMapSubdatasetNameToSwathGeolocationFieldMetadata - [osSubdatasetName] = oMetadata; + [osSubdatasetName] = std::move(oMetadata); } } } @@ -549,7 +550,8 @@ void HDF5EOSParser::ParseSwathStructure(const CPLJSONObject &oSwathStructure) m_oMapSubdatasetNameToSwathDataFieldMetadata ["//HDFEOS/SWATHS/" + osSwathName + - "/Data_Fields/" + osDataFieldName] = oMetadata; + "/Data_Fields/" + osDataFieldName] = + std::move(oMetadata); } } } diff --git a/frmts/hdf5/hdf5multidim.cpp b/frmts/hdf5/hdf5multidim.cpp index 2d37f79488a4..8e619d030cc9 100644 --- a/frmts/hdf5/hdf5multidim.cpp +++ b/frmts/hdf5/hdf5multidim.cpp @@ -1276,7 +1276,8 @@ void HDF5Array::InstantiateDimensions(const std::string &osParentName, if (ret > 0) { referenceName.resize(ret); - mapDimIndexToDimFullName[i] = referenceName; + mapDimIndexToDimFullName[i] = + std::move(referenceName); } } } @@ -2781,7 +2782,7 @@ GDALDataset *HDF5Dataset::OpenMultiDim(GDALOpenInfo *poOpenInfo) } auto poDS(new HDF5Dataset()); - poDS->m_poRootGroup = poGroup; + poDS->m_poRootGroup = std::move(poGroup); poDS->SetDescription(poOpenInfo->pszFilename); diff --git a/frmts/hf2/hf2dataset.cpp b/frmts/hf2/hf2dataset.cpp index f6d3a8c7a7a7..1a4adcd58f6a 100644 --- a/frmts/hf2/hf2dataset.cpp +++ b/frmts/hf2/hf2dataset.cpp @@ -659,7 +659,7 @@ GDALDataset *HF2Dataset::Open(GDALOpenInfo *poOpenInfo) oSRS.SetUTM(std::abs(static_cast(nUTMZone)), nUTMZone > 0); } if (bHasSRS) - poDS->m_oSRS = oSRS; + poDS->m_oSRS = std::move(oSRS); } /* -------------------------------------------------------------------- */ diff --git a/frmts/hfa/hfadataset.cpp b/frmts/hfa/hfadataset.cpp index b03742197140..5cd0fe219981 100644 --- a/frmts/hfa/hfadataset.cpp +++ b/frmts/hfa/hfadataset.cpp @@ -1651,7 +1651,7 @@ void HFARasterAttributeTable::RemoveStatistics() } } } - aoFields = aoNewFields; + aoFields = std::move(aoNewFields); } /************************************************************************/ @@ -4245,7 +4245,7 @@ CPLErr HFADataset::ReadProjection() CPLTestBool(CPLGetConfigOption("HFA_USE_ESRI_PE_STRING", "YES")) && oSRSFromPE.importFromWkt(pszPE_COORDSYS) == OGRERR_NONE) { - m_oSRS = oSRSFromPE; + m_oSRS = std::move(oSRSFromPE); // Copy TOWGS84 clause from HFA SRS to PE SRS. if (poSRS != nullptr) diff --git a/frmts/hfa/hfaopen.cpp b/frmts/hfa/hfaopen.cpp index eed333689a35..cac8b7a9c1ca 100644 --- a/frmts/hfa/hfaopen.cpp +++ b/frmts/hfa/hfaopen.cpp @@ -3750,9 +3750,9 @@ CPLErr HFARenameReferences(HFAHandle hHFA, const char *pszNewBase, { if (strncmp(aosNL[i], pszOldBase, strlen(pszOldBase)) == 0) { - CPLString osNew = pszNewBase; + std::string osNew = pszNewBase; osNew += aosNL[i].c_str() + strlen(pszOldBase); - aosNL[i] = osNew; + aosNL[i] = std::move(osNew); } } diff --git a/frmts/ilwis/ilwisdataset.cpp b/frmts/ilwis/ilwisdataset.cpp index 18914c4b089f..b27a80403922 100644 --- a/frmts/ilwis/ilwisdataset.cpp +++ b/frmts/ilwis/ilwisdataset.cpp @@ -73,9 +73,7 @@ static std::string GetLine(VSILFILE *fil) if (p == nullptr) return std::string(); - CPLString osWrk = p; - osWrk.Trim(); - return std::string(osWrk); + return CPLString(p).Trim(); } ////////////////////////////////////////////////////////////////////// diff --git a/frmts/jpegxl/jpegxl.cpp b/frmts/jpegxl/jpegxl.cpp index b8c2204f6be3..6d02817e0e00 100644 --- a/frmts/jpegxl/jpegxl.cpp +++ b/frmts/jpegxl/jpegxl.cpp @@ -889,7 +889,7 @@ bool JPEGXLDataset::Open(GDALOpenInfo *poOpenInfo) osName.size() + 1) == JXL_DEC_SUCCESS && osName != CPLSPrintf("Band %d", i)) { - osBandName = osName; + osBandName = std::move(osName); } } } diff --git a/frmts/kmlsuperoverlay/kmlsuperoverlaydataset.cpp b/frmts/kmlsuperoverlay/kmlsuperoverlaydataset.cpp index d434d515bd34..548a942ae8e0 100644 --- a/frmts/kmlsuperoverlay/kmlsuperoverlaydataset.cpp +++ b/frmts/kmlsuperoverlay/kmlsuperoverlaydataset.cpp @@ -1818,7 +1818,7 @@ static GDALDataset *KmlSuperOverlayLoadIcon(const char *pszBaseFilename, /* KmlSuperOverlayComputeDepth() */ /************************************************************************/ -static bool KmlSuperOverlayComputeDepth(CPLString osFilename, +static bool KmlSuperOverlayComputeDepth(const std::string &osFilename, CPLXMLNode *psDocument, int &nLevel) { CPLXMLNode *psIter = psDocument->psChild; @@ -1839,8 +1839,8 @@ static bool KmlSuperOverlayComputeDepth(CPLString osFilename, CPLSPrintf("/vsicurl_streaming/%s", pszHref); else { - osSubFilename = CPLFormFilename(CPLGetPath(osFilename), - pszHref, nullptr); + osSubFilename = CPLFormFilename( + CPLGetPath(osFilename.c_str()), pszHref, nullptr); osSubFilename = KMLRemoveSlash(osSubFilename); } @@ -2468,7 +2468,7 @@ GDALDataset *KmlSingleDocRasterDataset::Open(const char *pszFilename, poDS->SetBand(iBand, new KmlSingleDocRasterRasterBand(poDS, iBand)); poDS->SetDescription(pszFilename); poDS->SetMetadataItem("INTERLEAVE", "PIXEL", "IMAGE_STRUCTURE"); - poDS->aosDescs = aosDescs; + poDS->aosDescs = std::move(aosDescs); return poDS; } diff --git a/frmts/netcdf/netcdfdataset.cpp b/frmts/netcdf/netcdfdataset.cpp index 65161d8a6475..3a22f315c226 100644 --- a/frmts/netcdf/netcdfdataset.cpp +++ b/frmts/netcdf/netcdfdataset.cpp @@ -8443,7 +8443,7 @@ bool netCDFDatasetCreateTempFile(NetCDFFormatEnum eFormat, #endif oMapVarToId[pszVarName] = nVarId; oMapVarIdToType[nVarId] = nc_datatype; - oMapVarIdToVectorOfDimId[nVarId] = aoDimIds; + oMapVarIdToVectorOfDimId[nVarId] = std::move(aoDimIds); } } CSLDestroy(papszTokens); diff --git a/frmts/netcdf/netcdfmultidim.cpp b/frmts/netcdf/netcdfmultidim.cpp index 1acba8259fcd..6341ce706acf 100644 --- a/frmts/netcdf/netcdfmultidim.cpp +++ b/frmts/netcdf/netcdfmultidim.cpp @@ -4110,7 +4110,7 @@ netCDFVariable::GetCoordinateVariables() const auto poLat = poLocationGroup->OpenMDArray("lat"); if (poLon && poLat) { - return {poLon, poLat}; + return {std::move(poLon), std::move(poLat)}; } } } @@ -4542,7 +4542,7 @@ bool netCDFAttribute::IRead(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/ecrgtocdataset.cpp b/frmts/nitf/ecrgtocdataset.cpp index 0e3c76085c51..3671363ed6ed 100644 --- a/frmts/nitf/ecrgtocdataset.cpp +++ b/frmts/nitf/ecrgtocdataset.cpp @@ -123,8 +123,10 @@ class ECRGTOCDataset final : public GDALPamDataset } static GDALDataset *Build(const char *pszTOCFilename, CPLXMLNode *psXML, - CPLString osProduct, CPLString osDiscId, - CPLString osScale, const char *pszFilename); + const std::string &osProduct, + const std::string &osDiscId, + const std::string &osScale, + const char *pszFilename); static int Identify(GDALOpenInfo *poOpenInfo); static GDALDataset *Open(GDALOpenInfo *poOpenInfo); @@ -635,8 +637,10 @@ GDALDataset *ECRGTOCSubDataset::Build( /************************************************************************/ GDALDataset *ECRGTOCDataset::Build(const char *pszTOCFilename, - CPLXMLNode *psXML, CPLString osProduct, - CPLString osDiscId, CPLString osScale, + CPLXMLNode *psXML, + const std::string &osProduct, + const std::string &osDiscId, + const std::string &osScale, const char *pszOpenInfoFilename) { CPLXMLNode *psTOC = CPLGetXMLNode(psXML, "=Table_of_Contents"); diff --git a/frmts/ogcapi/gdalogcapidataset.cpp b/frmts/ogcapi/gdalogcapidataset.cpp index 10bd00450471..9cb83a6862f9 100644 --- a/frmts/ogcapi/gdalogcapidataset.cpp +++ b/frmts/ogcapi/gdalogcapidataset.cpp @@ -1923,8 +1923,9 @@ bool OGCAPIDataset::InitWithTilesAPI(GDALOpenInfo *poOpenInfo, bInvertAxis ? tileMatrix.mTopLeftX : tileMatrix.mTopLeftY; const auto CreateWMS_XML = - [=, &tileMatrix](int minRow, int rowCount, int nCoalesce, - double &dfStripMinY, double &dfStripMaxY) + [=, &osURL, &tileMatrix](int minRow, int rowCount, + int nCoalesce, double &dfStripMinY, + double &dfStripMaxY) { int minCol = 0; int maxCol = tileMatrix.mMatrixWidth - 1; diff --git a/frmts/pcidsk/sdk/core/cpcidskfile.cpp b/frmts/pcidsk/sdk/core/cpcidskfile.cpp index ab65cd45a3ed..ef51e9dfff63 100644 --- a/frmts/pcidsk/sdk/core/cpcidskfile.cpp +++ b/frmts/pcidsk/sdk/core/cpcidskfile.cpp @@ -1276,7 +1276,7 @@ std::map CPCIDSKFile::GetEDBChannelMap(std::string oExtFilename) void CPCIDSKFile::GetIODetails( void ***io_handle_pp, Mutex ***io_mutex_pp, - std::string filename, + const std::string& filename, bool writable ) { diff --git a/frmts/pcidsk/sdk/core/cpcidskfile.h b/frmts/pcidsk/sdk/core/cpcidskfile.h index b6feed5e108f..5ff0c6c3895d 100644 --- a/frmts/pcidsk/sdk/core/cpcidskfile.h +++ b/frmts/pcidsk/sdk/core/cpcidskfile.h @@ -94,7 +94,7 @@ namespace PCIDSK std::string GetFilename() const { return base_filename; } void GetIODetails( void ***io_handle_pp, Mutex ***io_mutex_pp, - std::string filename="", bool writable=false ) override; + const std::string& filename=std::string(), bool writable=false ) override; bool GetEDBFileDetails( EDBFile** file_p, Mutex **io_mutex_p, std::string filename ); diff --git a/frmts/pcidsk/sdk/core/pcidsk_utils.cpp b/frmts/pcidsk/sdk/core/pcidsk_utils.cpp index da0e8bb8aaf4..a3f8f201ac86 100644 --- a/frmts/pcidsk/sdk/core/pcidsk_utils.cpp +++ b/frmts/pcidsk/sdk/core/pcidsk_utils.cpp @@ -604,13 +604,11 @@ std::string PCIDSK::DefaultMergeRelativePath(const PCIDSK::IOInterfaces *io_inte /* -------------------------------------------------------------------- */ /* Merge paths. */ /* -------------------------------------------------------------------- */ - std::string base_path = ExtractPath( base ); - std::string result; + std::string result = ExtractPath( base ); - if( base_path == "" ) + if( result.empty() ) return src_filename; - result = base_path; result += path_split; result += src_filename; diff --git a/frmts/pcidsk/sdk/core/pcidskcreate.cpp b/frmts/pcidsk/sdk/core/pcidskcreate.cpp index d42635fe1c2c..d20de968b204 100644 --- a/frmts/pcidsk/sdk/core/pcidskcreate.cpp +++ b/frmts/pcidsk/sdk/core/pcidskcreate.cpp @@ -685,7 +685,7 @@ PCIDSK::Create( std::string filename, int pixels, int lines, interfaces->io->Close( band_io_handle ); // Set the channel header information. - channel->SetChanInfo( relative_band_filename, 0, pixel_size, + channel->SetChanInfo( std::move(relative_band_filename), 0, pixel_size, static_cast(pixel_size) * pixels, true ); } } diff --git a/frmts/pcidsk/sdk/pcidsk_file.h b/frmts/pcidsk/sdk/pcidsk_file.h index 092c485b26fb..3373fc48d382 100644 --- a/frmts/pcidsk/sdk/pcidsk_file.h +++ b/frmts/pcidsk/sdk/pcidsk_file.h @@ -116,7 +116,7 @@ namespace PCIDSK virtual void ReadFromFile( void *buffer, uint64 offset, uint64 size ) = 0; virtual void GetIODetails( void ***io_handle_pp, Mutex ***io_mutex_pp, - std::string filename="", bool writable=false ) = 0; + const std::string& filename=std::string(), bool writable=false ) = 0; virtual std::string GetUniqueEDBFilename() = 0; diff --git a/frmts/pcidsk/sdk/segment/metadatasegment_p.cpp b/frmts/pcidsk/sdk/segment/metadatasegment_p.cpp index e283711a945f..7caee9814fe0 100644 --- a/frmts/pcidsk/sdk/segment/metadatasegment_p.cpp +++ b/frmts/pcidsk/sdk/segment/metadatasegment_p.cpp @@ -172,7 +172,7 @@ void MetadataSegment::FetchGroupMetadata( const char *group, int id, else value.assign( pszNext+i_split+1, i-i_split-1 ); - md_set[key] = value; + md_set[key] = std::move(value); } /* -------------------------------------------------------------------- */ diff --git a/frmts/pdf/pdfdataset.cpp b/frmts/pdf/pdfdataset.cpp index 510c410220c6..c94d523cd010 100644 --- a/frmts/pdf/pdfdataset.cpp +++ b/frmts/pdf/pdfdataset.cpp @@ -3621,11 +3621,15 @@ void PDFDataset::ExploreLayersPoppler(GDALPDFArray *poArray, continue; if (i == 0 && poObj->GetType() == PDFObjectType_String) { - CPLString osName = PDFSanitizeLayerName(poObj->GetString().c_str()); + std::string osName = + PDFSanitizeLayerName(poObj->GetString().c_str()); if (!osTopLayer.empty()) - osTopLayer = osTopLayer + "." + osName; + { + osTopLayer += '.'; + osTopLayer += osName; + } else - osTopLayer = osName; + osTopLayer = std::move(osName); AddLayer(osTopLayer.c_str()); m_oLayerOCGListPoppler.push_back(std::pair(osTopLayer, nullptr)); } @@ -3643,13 +3647,17 @@ void PDFDataset::ExploreLayersPoppler(GDALPDFArray *poArray, GDALPDFObject *poName = poDict->Get("Name"); if (poName != nullptr && poName->GetType() == PDFObjectType_String) { - CPLString osName = + std::string osName = PDFSanitizeLayerName(poName->GetString().c_str()); /* coverity[copy_paste_error] */ if (!osTopLayer.empty()) - osCurLayer = osTopLayer + "." + osName; + { + osCurLayer = osTopLayer; + osCurLayer += '.'; + osCurLayer += osName; + } else - osCurLayer = osName; + osCurLayer = std::move(osName); // CPLDebug("PDF", "Layer %s", osCurLayer.c_str()); OCGs *optContentConfig = m_poDocPoppler->getOptContentConfig(); diff --git a/frmts/pdf/pdfobject.cpp b/frmts/pdf/pdfobject.cpp index 23e550dbaf33..7817a67bb528 100644 --- a/frmts/pdf/pdfobject.cpp +++ b/frmts/pdf/pdfobject.cpp @@ -2522,7 +2522,7 @@ GDALPDFStream *GDALPDFObjectPdfium::GetStream() auto pStream = pdfium::WrapRetain(m_obj->AsStream()); if (pStream) { - m_poStream = new GDALPDFStreamPdfium(pStream); + m_poStream = new GDALPDFStreamPdfium(std::move(pStream)); return m_poStream; } else diff --git a/frmts/pdf/pdfreadvectors.cpp b/frmts/pdf/pdfreadvectors.cpp index 0a0e8fa028ac..b9c4045c74c0 100644 --- a/frmts/pdf/pdfreadvectors.cpp +++ b/frmts/pdf/pdfreadvectors.cpp @@ -280,14 +280,14 @@ bool PDFDataset::ExploreTree(GDALPDFObject *poObj, GDALPDFDictionary *poDict = poObj->GetDictionary(); GDALPDFObject *poS = poDict->Get("S"); - CPLString osS; + std::string osS; if (poS != nullptr && poS->GetType() == PDFObjectType_Name) { osS = poS->GetName(); } GDALPDFObject *poT = poDict->Get("T"); - CPLString osT; + std::string osT; if (poT != nullptr && poT->GetType() == PDFObjectType_String) { osT = poT->GetString(); @@ -330,13 +330,13 @@ bool PDFDataset::ExploreTree(GDALPDFObject *poObj, return false; } - CPLString osLayerName; + std::string osLayerName; if (!osT.empty()) - osLayerName = osT; + osLayerName = std::move(osT); else { if (!osS.empty()) - osLayerName = osS; + osLayerName = std::move(osS); else osLayerName = CPLSPrintf("Layer%d", m_nLayers + 1); } diff --git a/frmts/pds/isis2dataset.cpp b/frmts/pds/isis2dataset.cpp index 9836019aa61d..06bf83002bee 100644 --- a/frmts/pds/isis2dataset.cpp +++ b/frmts/pds/isis2dataset.cpp @@ -93,12 +93,13 @@ class ISIS2Dataset final : public RawDataset char **papszParamList); // Write related. - static int WriteRaster(CPLString osFilename, bool includeLabel, + static int WriteRaster(const std::string &osFilename, bool includeLabel, GUIntBig iRecord, GUIntBig iLabelRecords, GDALDataType eType, const char *pszInterleaving); - static int WriteLabel(CPLString osFilename, CPLString osRasterFile, - CPLString sObjectTag, unsigned int nXSize, + static int WriteLabel(const std::string &osFilename, + const std::string &osRasterFile, + const std::string &sObjectTag, unsigned int nXSize, unsigned int nYSize, unsigned int nBandsIn, GDALDataType eType, GUIntBig iRecords, const char *pszInterleaving, GUIntBig &iLabelRecords, @@ -986,16 +987,12 @@ GDALDataset *ISIS2Dataset::Create(const char *pszFilename, int nXSize, /* WriteRaster() */ /************************************************************************/ -int ISIS2Dataset::WriteRaster(CPLString osFilename, bool includeLabel, +int ISIS2Dataset::WriteRaster(const std::string &osFilename, bool includeLabel, GUIntBig iRecords, GUIntBig iLabelRecords, CPL_UNUSED GDALDataType eType, CPL_UNUSED const char *pszInterleaving) { - CPLString pszAccess("wb"); - if (includeLabel) - pszAccess = "ab"; - - VSILFILE *fpBin = VSIFOpenL(osFilename, pszAccess.c_str()); + VSILFILE *fpBin = VSIFOpenL(osFilename.c_str(), includeLabel ? "ab" : "wb"); if (fpBin == nullptr) { CPLError(CE_Failure, CPLE_FileIO, "Failed to create %s:\n%s", @@ -1142,8 +1139,9 @@ int ISIS2Dataset::WriteQUBE_Information( /* bRelaunch : flag to allow recursive call */ /************************************************************************/ -int ISIS2Dataset::WriteLabel(CPLString osFilename, CPLString osRasterFile, - CPLString sObjectTag, unsigned int nXSize, +int ISIS2Dataset::WriteLabel(const std::string &osFilename, + const std::string &osRasterFile, + const std::string &sObjectTag, unsigned int nXSize, unsigned int nYSize, unsigned int nBandsIn, GDALDataType eType, GUIntBig iRecords, const char *pszInterleaving, @@ -1151,9 +1149,9 @@ int ISIS2Dataset::WriteLabel(CPLString osFilename, CPLString osRasterFile, { CPLDebug("ISIS2", "Write Label filename = %s, rasterfile = %s", osFilename.c_str(), osRasterFile.c_str()); - bool bAttachedLabel = EQUAL(osRasterFile, ""); + bool bAttachedLabel = EQUAL(osRasterFile.c_str(), ""); - VSILFILE *fpLabel = VSIFOpenL(osFilename, "w"); + VSILFILE *fpLabel = VSIFOpenL(osFilename.c_str(), "w"); if (fpLabel == nullptr) { @@ -1184,7 +1182,7 @@ int ISIS2Dataset::WriteLabel(CPLString osFilename, CPLString osRasterFile, if (!bAttachedLabel) { nWritingBytes += ISIS2Dataset::WriteKeyword( - fpLabel, iLevel, "FILE_NAME", CPLGetFilename(osRasterFile)); + fpLabel, iLevel, "FILE_NAME", CPLGetFilename(osRasterFile.c_str())); } nWritingBytes += ISIS2Dataset::WriteFormatting(fpLabel, ""); @@ -1201,10 +1199,11 @@ int ISIS2Dataset::WriteLabel(CPLString osFilename, CPLString osRasterFile, { nWritingBytes += ISIS2Dataset::WriteKeyword( fpLabel, iLevel, CPLString().Printf("^%s", sObjectTag.c_str()), - CPLString().Printf("(\"%s\",1)", CPLGetFilename(osRasterFile))); + CPLString().Printf("(\"%s\",1)", + CPLGetFilename(osRasterFile.c_str()))); } - if (EQUAL(sObjectTag, "QUBE")) + if (EQUAL(sObjectTag.c_str(), "QUBE")) { ISIS2Dataset::WriteQUBE_Information(fpLabel, iLevel, nWritingBytes, nXSize, nYSize, nBandsIn, eType, diff --git a/frmts/pds/isis3dataset.cpp b/frmts/pds/isis3dataset.cpp index 6b9de1580dc8..fa6d07621221 100644 --- a/frmts/pds/isis3dataset.cpp +++ b/frmts/pds/isis3dataset.cpp @@ -2476,7 +2476,7 @@ GDALDataset *ISIS3Dataset::Open(GDALOpenInfo *poOpenInfo) if (oSRS2.importFromESRI(papszLines) == OGRERR_NONE) { poDS->m_aosAdditionalFiles.AddString(pszPrjFile); - poDS->m_oSRS = oSRS2; + poDS->m_oSRS = std::move(oSRS2); poDS->m_oSRS.SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER); } @@ -3161,7 +3161,7 @@ void ISIS3Dataset::BuildLabel() "!*^PLACEHOLDER_%d_STARTBYTE^*!", static_cast(m_aoNonPixelSections.size()) + 1); oObj.Set("StartByte", osPlaceHolder); - oSection.osPlaceHolder = osPlaceHolder; + oSection.osPlaceHolder = std::move(osPlaceHolder); } if (!m_osExternalFilename.empty()) @@ -4005,7 +4005,7 @@ GDALDataset *ISIS3Dataset::Create(const char *pszFilename, int nXSize, return nullptr; } VSILFILE *fpImage = nullptr; - CPLString osExternalFilename; + std::string osExternalFilename; GDALDataset *poExternalDS = nullptr; bool bGeoTIFFAsRegularExternal = false; if (EQUAL(pszDataLocation, "EXTERNAL")) @@ -4013,7 +4013,7 @@ GDALDataset *ISIS3Dataset::Create(const char *pszFilename, int nXSize, osExternalFilename = CSLFetchNameValueDef(papszOptions, "EXTERNAL_FILENAME", CPLResetExtension(pszFilename, "cub")); - fpImage = VSIFOpenExL(osExternalFilename, "wb", true); + fpImage = VSIFOpenExL(osExternalFilename.c_str(), "wb", true); if (fpImage == nullptr) { CPLError(CE_Failure, CPLE_FileIO, "Cannot create %s: %s", @@ -4077,7 +4077,7 @@ GDALDataset *ISIS3Dataset::Create(const char *pszFilename, int nXSize, } } - poExternalDS = poDrv->Create(osExternalFilename, nXSize, nYSize, + poExternalDS = poDrv->Create(osExternalFilename.c_str(), nXSize, nYSize, nBandsIn, eType, papszGTiffOptions); CSLDestroy(papszGTiffOptions); if (poExternalDS == nullptr) @@ -4094,7 +4094,7 @@ GDALDataset *ISIS3Dataset::Create(const char *pszFilename, int nXSize, poDS->eAccess = GA_Update; poDS->nRasterXSize = nXSize; poDS->nRasterYSize = nYSize; - poDS->m_osExternalFilename = osExternalFilename; + poDS->m_osExternalFilename = std::move(osExternalFilename); poDS->m_poExternalDS = poExternalDS; poDS->m_bGeoTIFFAsRegularExternal = bGeoTIFFAsRegularExternal; if (bGeoTIFFAsRegularExternal) diff --git a/frmts/pds/pds4dataset.cpp b/frmts/pds/pds4dataset.cpp index be5b7d916c60..8689164a838b 100644 --- a/frmts/pds/pds4dataset.cpp +++ b/frmts/pds/pds4dataset.cpp @@ -1380,7 +1380,7 @@ void PDS4Dataset::ReadGeoreferencing(CPLXMLNode *psProduct) { if (GetRasterCount()) { - m_oSRS = oSRS; + m_oSRS = std::move(oSRS); } else if (GetLayerCount()) { @@ -4565,14 +4565,14 @@ PDS4Dataset *PDS4Dataset::CreateInternal(const char *pszFilename, poDS->nRasterXSize = nXSize; poDS->nRasterYSize = nYSize; poDS->eAccess = GA_Update; - poDS->m_osImageFilename = osImageFilename; + poDS->m_osImageFilename = std::move(osImageFilename); poDS->m_bCreateHeader = true; poDS->m_bStripFileAreaObservationalFromTemplate = true; poDS->m_osInterleave = pszInterleave; poDS->m_papszCreationOptions = CSLDuplicate(aosOptions.List()); poDS->m_bUseSrcLabel = aosOptions.FetchBool("USE_SRC_LABEL", true); poDS->m_bIsLSB = bIsLSB; - poDS->m_osHeaderParsingStandard = osHeaderParsingStandard; + poDS->m_osHeaderParsingStandard = std::move(osHeaderParsingStandard); poDS->m_bCreatedFromExistingBinaryFile = bCreateLabelOnly; if (EQUAL(pszInterleave, "BIP")) diff --git a/frmts/pds/pdsdataset.cpp b/frmts/pds/pdsdataset.cpp index 032e7de259dd..8553784517c1 100644 --- a/frmts/pds/pdsdataset.cpp +++ b/frmts/pds/pdsdataset.cpp @@ -1455,7 +1455,7 @@ GDALDataset *PDSDataset::Open(GDALOpenInfo *poOpenInfo) 0) { osFilenamePrefix = "/vsizip/" + osCompressedFilename + "/"; - poDS->osExternalCube = osCompressedFilename; + poDS->osExternalCube = std::move(osCompressedFilename); } osEncodingType = ""; } diff --git a/frmts/pds/vicardataset.cpp b/frmts/pds/vicardataset.cpp index b39d5c531b24..634866123135 100644 --- a/frmts/pds/vicardataset.cpp +++ b/frmts/pds/vicardataset.cpp @@ -3270,7 +3270,7 @@ VICARDataset *VICARDataset::CreateInternal(const char *pszFilename, int nXSize, poDS->m_osTargetName = CSLFetchNameValueDef(papszOptions, "TARGET_NAME", ""); poDS->m_bInitToNodata = true; - poDS->m_oSrcJSonLabel = oSrcJSonLabel; + poDS->m_oSrcJSonLabel = std::move(oSrcJSonLabel); poDS->m_eCompress = eCompress; poDS->m_anRecordOffsets = std::move(anRecordOffsets); poDS->eAccess = GA_Update; diff --git a/frmts/postgisraster/postgisrasterdataset.cpp b/frmts/postgisraster/postgisrasterdataset.cpp index f17a531087f9..5665c960244c 100644 --- a/frmts/postgisraster/postgisrasterdataset.cpp +++ b/frmts/postgisraster/postgisrasterdataset.cpp @@ -1207,10 +1207,11 @@ GBool PostGISRasterDataset::LoadSources(int nXOff, int nYOff, int nXSize, CPLTestBool(CPLGetConfigOption("PR_FORCE_LOAD_RASTERS", "FALSE")); bool bAllBandCaching = false; - CPLString osPrimaryKeyNameI(CPLQuotedSQLIdentifier(pszPrimaryKeyName)); - CPLString osSchemaI(CPLQuotedSQLIdentifier(pszSchema)); - CPLString osTableI(CPLQuotedSQLIdentifier(pszTable)); - CPLString osColumnI(CPLQuotedSQLIdentifier(pszColumn)); + const std::string osPrimaryKeyNameI( + CPLQuotedSQLIdentifier(pszPrimaryKeyName)); + const std::string osSchemaI(CPLQuotedSQLIdentifier(pszSchema)); + const std::string osTableI(CPLQuotedSQLIdentifier(pszTable)); + const std::string osColumnI(CPLQuotedSQLIdentifier(pszColumn)); PGresult *poResult = nullptr; if (m_nTiles > 0 && !bFetchAll) @@ -1298,7 +1299,7 @@ GBool PostGISRasterDataset::LoadSources(int nXOff, int nYOff, int nXSize, if (bFetchAll || !osIDsToFetch.empty() || !osSpatialFilter.empty()) { - CPLString osWHERE; + std::string osWHERE; if (!osIDsToFetch.empty()) { osWHERE += osPrimaryKeyNameI; @@ -1308,7 +1309,7 @@ GBool PostGISRasterDataset::LoadSources(int nXOff, int nYOff, int nXSize, } else if (!osSpatialFilter.empty()) { - osWHERE = osSpatialFilter; + osWHERE = std::move(osSpatialFilter); } if (pszWhere != nullptr) { diff --git a/frmts/raw/btdataset.cpp b/frmts/raw/btdataset.cpp index 7f18de646a94..41eb0cd43769 100644 --- a/frmts/raw/btdataset.cpp +++ b/frmts/raw/btdataset.cpp @@ -753,7 +753,7 @@ GDALDataset *BTDataset::Open(GDALOpenInfo *poOpenInfo) /* Convert coordinate system back to WKT. */ /* -------------------------------------------------------------------- */ if (oSRS.GetRoot() != nullptr) - poDS->m_oSRS = oSRS; + poDS->m_oSRS = std::move(oSRS); /* -------------------------------------------------------------------- */ /* Get georeferencing bounds. */ diff --git a/frmts/raw/envidataset.cpp b/frmts/raw/envidataset.cpp index 681ccbd4df8c..26b924e3b19a 100644 --- a/frmts/raw/envidataset.cpp +++ b/frmts/raw/envidataset.cpp @@ -1598,7 +1598,7 @@ bool ENVIDataset::ProcessMapinfo(const char *pszMapinfo) } else { - m_oSRS = oSRS; + m_oSRS = std::move(oSRS); } m_oSRS.SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER); @@ -2424,7 +2424,7 @@ ENVIDataset *ENVIDataset::Open(GDALOpenInfo *poOpenInfo, bool bFileSizeCheck) for (int i = 0; i < nBands; i++) { // First set up the wavelength names and units if available. - CPLString osWavelength; + std::string osWavelength; if (papszWL && nWLCount > i) { osWavelength = papszWL[i]; @@ -2436,7 +2436,7 @@ ENVIDataset *ENVIDataset::Open(GDALOpenInfo *poOpenInfo, bool bFileSizeCheck) } // Build the final name for this band. - CPLString osBandName; + std::string osBandName; if (papszBandNames && CSLCount(papszBandNames) > i) { osBandName = papszBandNames[i]; @@ -2450,15 +2450,15 @@ ENVIDataset *ENVIDataset::Open(GDALOpenInfo *poOpenInfo, bool bFileSizeCheck) else { // WL but no band names. - osBandName = osWavelength; + osBandName = std::move(osWavelength); } // Description is for internal GDAL usage. - poDS->GetRasterBand(i + 1)->SetDescription(osBandName); + poDS->GetRasterBand(i + 1)->SetDescription(osBandName.c_str()); // Metadata field named Band_1, etc. Needed for ArcGIS integration. CPLString osBandId = CPLSPrintf("Band_%i", i + 1); - poDS->SetMetadataItem(osBandId, osBandName); + poDS->SetMetadataItem(osBandId, osBandName.c_str()); // Set wavelength metadata to band. if (papszWL && nWLCount > i) diff --git a/frmts/raw/rrasterdataset.cpp b/frmts/raw/rrasterdataset.cpp index 9296d498b51f..f4aef1c7f81a 100644 --- a/frmts/raw/rrasterdataset.cpp +++ b/frmts/raw/rrasterdataset.cpp @@ -1041,6 +1041,8 @@ GDALDataset *RRASTERDataset::Open(GDALOpenInfo *poOpenInfo) if (!Identify(poOpenInfo)) return nullptr; + auto poDS = std::make_unique(); + const char *pszLine = nullptr; int nRows = 0; int nCols = 0; @@ -1050,21 +1052,17 @@ GDALDataset *RRASTERDataset::Open(GDALOpenInfo *poOpenInfo) double dfYMax = 0.0; int l_nBands = 1; CPLString osDataType; - CPLString osBandOrder; CPLString osProjection; CPLString osWkt; CPLString osByteOrder; CPLString osNoDataValue("NA"); CPLString osMinValue; CPLString osMaxValue; - CPLString osCreator; - CPLString osCreated; CPLString osLayerName; CPLString osRatNames; CPLString osRatTypes; CPLString osRatValues; bool bInLegend = false; - CPLString osLegend; VSIRewindL(poOpenInfo->fpL); while ((pszLine = CPLReadLine2L(poOpenInfo->fpL, 1024 * 1024, nullptr)) != nullptr) @@ -1076,17 +1074,17 @@ GDALDataset *RRASTERDataset::Open(GDALOpenInfo *poOpenInfo) } if (bInLegend) { - osLegend += pszLine; - osLegend += "\n"; + poDS->m_osLegend += pszLine; + poDS->m_osLegend += "\n"; } char *pszKey = nullptr; const char *pszValue = CPLParseNameValue(pszLine, &pszKey); if (pszKey && pszValue) { if (EQUAL(pszKey, "creator")) - osCreator = pszValue; + poDS->m_osCreator = pszValue; if (EQUAL(pszKey, "created")) - osCreated = pszValue; + poDS->m_osCreated = pszValue; else if (EQUAL(pszKey, "ncols")) nCols = atoi(pszValue); else if (EQUAL(pszKey, "nrows")) @@ -1106,7 +1104,7 @@ GDALDataset *RRASTERDataset::Open(GDALOpenInfo *poOpenInfo) else if (EQUAL(pszKey, "nbands")) l_nBands = atoi(pszValue); else if (EQUAL(pszKey, "bandorder")) - osBandOrder = pszValue; + poDS->m_osBandOrder = pszValue; else if (EQUAL(pszKey, "datatype")) osDataType = pszValue; else if (EQUAL(pszKey, "byteorder")) @@ -1160,7 +1158,7 @@ GDALDataset *RRASTERDataset::Open(GDALOpenInfo *poOpenInfo) osDataType.c_str()); return nullptr; } - if (l_nBands > 1 && osBandOrder.empty()) + if (l_nBands > 1 && poDS->m_osBandOrder.empty()) { CPLError(CE_Failure, CPLE_AppDefined, "Missing 'bandorder'"); return nullptr; @@ -1185,13 +1183,12 @@ GDALDataset *RRASTERDataset::Open(GDALOpenInfo *poOpenInfo) int nPixelOffset = 0; int nLineOffset = 0; vsi_l_offset nBandOffset = 0; - if (!ComputeSpacings(osBandOrder, nCols, nRows, l_nBands, eDT, nPixelOffset, - nLineOffset, nBandOffset)) + if (!ComputeSpacings(poDS->m_osBandOrder, nCols, nRows, l_nBands, eDT, + nPixelOffset, nLineOffset, nBandOffset)) { return nullptr; } - CPLString osGriFilename; CPLString osDirname(CPLGetDirname(poOpenInfo->pszFilename)); CPLString osBasename(CPLGetBasename(poOpenInfo->pszFilename)); CPLString osGRDExtension(CPLGetExtension(poOpenInfo->pszFilename)); @@ -1204,20 +1201,22 @@ GDALDataset *RRASTERDataset::Open(GDALOpenInfo *poOpenInfo) CPLFormFilename(nullptr, osBasename, osGRIExtension)); if (iFile < 0) return nullptr; - osGriFilename = + poDS->m_osGriFilename = CPLFormFilename(osDirname, papszSiblings[iFile], nullptr); } else { - osGriFilename = CPLFormFilename(osDirname, osBasename, osGRIExtension); + poDS->m_osGriFilename = + CPLFormFilename(osDirname, osBasename, osGRIExtension); } - VSILFILE *fpImage = VSIFOpenL( - osGriFilename, (poOpenInfo->eAccess == GA_Update) ? "rb+" : "rb"); + VSILFILE *fpImage = + VSIFOpenL(poDS->m_osGriFilename, + (poOpenInfo->eAccess == GA_Update) ? "rb+" : "rb"); if (fpImage == nullptr) { CPLError(CE_Failure, CPLE_FileIO, "Cannot open %s", - osGriFilename.c_str()); + poDS->m_osGriFilename.c_str()); return nullptr; } @@ -1229,7 +1228,6 @@ GDALDataset *RRASTERDataset::Open(GDALOpenInfo *poOpenInfo) return nullptr; } - auto poDS = std::make_unique(); poDS->eAccess = poOpenInfo->eAccess; poDS->nRasterXSize = nCols; poDS->nRasterYSize = nRows; @@ -1240,13 +1238,8 @@ GDALDataset *RRASTERDataset::Open(GDALOpenInfo *poOpenInfo) poDS->m_adfGeoTransform[3] = dfYMax; poDS->m_adfGeoTransform[4] = 0.0; poDS->m_adfGeoTransform[5] = -(dfYMax - dfYMin) / nRows; - poDS->m_osGriFilename = osGriFilename; poDS->m_fpImage = fpImage; poDS->m_bNativeOrder = bNativeOrder; - poDS->m_osCreator = osCreator; - poDS->m_osCreated = osCreated; - poDS->m_osBandOrder = osBandOrder; - poDS->m_osLegend = osLegend; if (osWkt.empty()) { @@ -1260,11 +1253,11 @@ GDALDataset *RRASTERDataset::Open(GDALOpenInfo *poOpenInfo) poDS->m_oSRS.importFromWkt(osWkt.c_str()); } - if (!osCreator.empty()) - poDS->GDALDataset::SetMetadataItem("CREATOR", osCreator); + if (!poDS->m_osCreator.empty()) + poDS->GDALDataset::SetMetadataItem("CREATOR", poDS->m_osCreator); - if (!osCreated.empty()) - poDS->GDALDataset::SetMetadataItem("CREATED", osCreated); + if (!poDS->m_osCreated.empty()) + poDS->GDALDataset::SetMetadataItem("CREATED", poDS->m_osCreated); // Instantiate RAT if (!osRatNames.empty() && !osRatTypes.empty() && !osRatValues.empty()) diff --git a/frmts/stacit/stacitdataset.cpp b/frmts/stacit/stacitdataset.cpp index eae8b84faee4..5ebe50b4c35a 100644 --- a/frmts/stacit/stacitdataset.cpp +++ b/frmts/stacit/stacitdataset.cpp @@ -374,7 +374,7 @@ static void ParseAsset(const CPLJSONObject &jAsset, asset.osName = osAssetName; asset.eoBands = jAsset.GetArray("eo:bands"); - collection.assets[osAssetName] = asset; + collection.assets[osAssetName] = std::move(asset); } auto &asset = collection.assets[osAssetName]; @@ -383,7 +383,7 @@ static void ParseAsset(const CPLJSONObject &jAsset, { AssetSetByProjection assetByProj; assetByProj.osProjUserString = osProjUserString; - asset.assets[osProjUserString] = assetByProj; + asset.assets[osProjUserString] = std::move(assetByProj); } auto &assets = asset.assets[osProjUserString]; diff --git a/frmts/tga/tgadataset.cpp b/frmts/tga/tgadataset.cpp index 465a5aed4c09..2316ed9b963f 100644 --- a/frmts/tga/tgadataset.cpp +++ b/frmts/tga/tgadataset.cpp @@ -463,7 +463,8 @@ CPLErr GDALTGARasterBand::IReadBlock(int /* nBlockXOff */, int nBlockYOff, poGDS->m_aoScanlineState[nLine + 1].nRemainingPixelsPrevScanline = nRemainingPixelsPrevScanline; if (nRemainingPixelsPrevScanline) - poGDS->m_aoScanlineState[nLine + 1].abyDataPrevRLERun = abyData; + poGDS->m_aoScanlineState[nLine + 1].abyDataPrevRLERun = + std::move(abyData); } if (pImage && nBands == 1) { diff --git a/frmts/tiledb/tiledbmultidimarray.cpp b/frmts/tiledb/tiledbmultidimarray.cpp index 0f15e94bf681..302253d0ebf8 100644 --- a/frmts/tiledb/tiledbmultidimarray.cpp +++ b/frmts/tiledb/tiledbmultidimarray.cpp @@ -341,8 +341,9 @@ std::shared_ptr TileDBArray::OpenFromDisk( return nullptr; } - auto attr = osAttributeName.empty() ? schema.attribute(0) - : schema.attribute(osAttributeName); + const auto &attr = osAttributeName.empty() + ? schema.attribute(0) + : schema.attribute(osAttributeName); GDALDataType eDT = TileDBDataTypeToGDALDataType(attr.type()); if (eDT == GDT_Unknown) { @@ -680,8 +681,8 @@ std::shared_ptr TileDBArray::OpenFromDisk( poArray->m_anBlockSize = std::move(anBlockSize); poArray->m_anStartDimOffset = std::move(anStartDimOffset); poArray->m_osAttrName = attr.name(); - poArray->m_osUnit = osUnit; - poArray->m_poSRS = poSRS; + poArray->m_osUnit = std::move(osUnit); + poArray->m_poSRS = std::move(poSRS); poArray->m_nTimestamp = nTimestamp; const auto filters = attr.filter_list(); @@ -1384,7 +1385,7 @@ std::shared_ptr TileDBArray::CreateOnDisk( poArray->m_poSchema = std::move(poSchema); poArray->m_osAttrName = attr->name(); poArray->m_poAttr = std::move(attr); - poArray->m_anBlockSize = anBlockSize; + poArray->m_anBlockSize = std::move(anBlockSize); poArray->m_anStartDimOffset.resize(aoDimensions.size()); // To keep a reference on the indexing variables, so they are still // alive at Finalize() time diff --git a/frmts/tiledb/tiledbmultidimgroup.cpp b/frmts/tiledb/tiledbmultidimgroup.cpp index b44a084b592a..55f5fee660ea 100644 --- a/frmts/tiledb/tiledbmultidimgroup.cpp +++ b/frmts/tiledb/tiledbmultidimgroup.cpp @@ -476,7 +476,7 @@ TileDBGroup::OpenMDArray(const std::string &osName, } } if (osSubPath.empty()) - osSubPath = osSubPathCandidate; + osSubPath = std::move(osSubPathCandidate); if (osSubPath.empty()) return nullptr; diff --git a/frmts/vrt/vrtmultidim.cpp b/frmts/vrt/vrtmultidim.cpp index 6420805712c6..2ecf9045a7a3 100644 --- a/frmts/vrt/vrtmultidim.cpp +++ b/frmts/vrt/vrtmultidim.cpp @@ -1121,7 +1121,7 @@ std::shared_ptr VRTMDArray::Create(const char *pszVRTPath, std::shared_ptr(new VRTGroup(pszVRTPath ? pszVRTPath : "")); auto poArray = Create(poDummyGroup, std::string(), psNode); if (poArray) - poArray->m_poDummyOwningGroup = poDummyGroup; + poArray->m_poDummyOwningGroup = std::move(poDummyGroup); return poArray; } @@ -1984,7 +1984,7 @@ bool VRTMDArraySourceFromArray::Read(const GUInt64 *arrayStartIdx, if (!poSrcDS) return false; poSrcDSWrapper = std::make_shared(poSrcDS); - oPair.first = poSrcDSWrapper; + oPair.first = std::move(poSrcDSWrapper); oPair.second.insert(this); g_cacheSources.insert(key, oPair); } diff --git a/frmts/wcs/wcsdataset.cpp b/frmts/wcs/wcsdataset.cpp index b1e730fabdb2..1e5747e35f44 100644 --- a/frmts/wcs/wcsdataset.cpp +++ b/frmts/wcs/wcsdataset.cpp @@ -745,12 +745,9 @@ GDALDataset *WCSDataset::GDALOpenResult(CPLHTTPResult *psResult) /* -------------------------------------------------------------------- */ if (poDS == nullptr) { - std::string osTempFilename; - VSILFILE *fpTemp; - - osTempFilename = CPLString().Printf("/tmp/%p_wcs.dat", this); - - fpTemp = VSIFOpenL(osTempFilename.c_str(), "wb"); + const std::string osTempFilename = + CPLString().Printf("/tmp/%p_wcs.dat", this); + VSILFILE *fpTemp = VSIFOpenL(osTempFilename.c_str(), "wb"); if (fpTemp == nullptr) { CPLError(CE_Failure, CPLE_OpenFailed, diff --git a/frmts/wcs/wcsdataset110.cpp b/frmts/wcs/wcsdataset110.cpp index 28bf08363b06..9b9f916c4909 100644 --- a/frmts/wcs/wcsdataset110.cpp +++ b/frmts/wcs/wcsdataset110.cpp @@ -697,7 +697,7 @@ CPLErr WCSDataset110::ParseCapabilities(CPLXMLNode *Capabilities, } char **metadata = nullptr; - CPLString path = "WCS_GLOBAL#"; + std::string path = "WCS_GLOBAL#"; CPLString key = path + "version"; metadata = CSLSetNameValue(metadata, key, Version()); @@ -715,14 +715,10 @@ CPLErr WCSDataset110::ParseCapabilities(CPLXMLNode *Capabilities, } // identification metadata - CPLString path2 = path; - std::vector keys2; - keys2.push_back("Title"); - keys2.push_back("Abstract"); - keys2.push_back("Fees"); - keys2.push_back("AccessConstraints"); - CPLXMLNode *service = AddSimpleMetaData(&metadata, Capabilities, path2, - "ServiceIdentification", keys2); + std::string path2 = path; + CPLXMLNode *service = AddSimpleMetaData( + &metadata, Capabilities, path2, "ServiceIdentification", + {"Title", "Abstract", "Fees", "AccessConstraints"}); CPLString kw = GetKeywords(service, "Keywords", "Keyword"); if (kw != "") { @@ -738,51 +734,38 @@ CPLErr WCSDataset110::ParseCapabilities(CPLXMLNode *Capabilities, // provider metadata path2 = path; - keys2.clear(); - keys2.push_back("ProviderName"); - CPLXMLNode *provider = AddSimpleMetaData(&metadata, Capabilities, path2, - "ServiceProvider", keys2); + CPLXMLNode *provider = AddSimpleMetaData( + &metadata, Capabilities, path2, "ServiceProvider", {"ProviderName"}); if (provider) { CPLXMLNode *site = CPLGetXMLNode(provider, "ProviderSite"); if (site) { - CPLString path3 = path2 + "ProviderSite"; + std::string path3 = path2 + "ProviderSite"; CPLString value = CPLGetXMLValue(CPLGetXMLNode(site, "href"), nullptr, ""); - metadata = CSLSetNameValue(metadata, path3, value); + metadata = CSLSetNameValue(metadata, path3.c_str(), value); } - CPLString path3 = path2; - std::vector keys3; - keys3.push_back("IndividualName"); - keys3.push_back("PositionName"); - keys3.push_back("Role"); - CPLXMLNode *contact = AddSimpleMetaData(&metadata, provider, path3, - "ServiceContact", keys3); + std::string path3 = std::move(path2); + CPLXMLNode *contact = + AddSimpleMetaData(&metadata, provider, path3, "ServiceContact", + {"IndividualName", "PositionName", "Role"}); if (contact) { - CPLString path4 = path3; - std::vector keys4; - keys4.push_back("HoursOfService"); - keys4.push_back("ContactInstructions"); - CPLXMLNode *info = AddSimpleMetaData(&metadata, contact, path4, - "ContactInfo", keys4); + std::string path4 = std::move(path3); + CPLXMLNode *info = + AddSimpleMetaData(&metadata, contact, path4, "ContactInfo", + {"HoursOfService", "ContactInstructions"}); if (info) { - CPLString path5 = path4; - std::vector keys5; - keys5.push_back("DeliveryPoint"); - keys5.push_back("City"); - keys5.push_back("AdministrativeArea"); - keys5.push_back("PostalCode"); - keys5.push_back("Country"); - keys5.push_back("ElectronicMailAddress"); - CPLString path6 = path4; - std::vector keys6; - keys6.push_back("Voice"); - keys6.push_back("Facsimile"); - AddSimpleMetaData(&metadata, info, path5, "Address", keys5); - AddSimpleMetaData(&metadata, info, path6, "Phone", keys6); + std::string path5 = path4; + std::string path6 = path4; + AddSimpleMetaData(&metadata, info, path5, "Address", + {"DeliveryPoint", "City", + "AdministrativeArea", "PostalCode", + "Country", "ElectronicMailAddress"}); + AddSimpleMetaData(&metadata, info, path6, "Phone", + {"Voice", "Facsimile"}); } } } @@ -882,7 +865,7 @@ CPLErr WCSDataset110::ParseCapabilities(CPLXMLNode *Capabilities, name = CPLURLAddKVP(name, "version", this->Version()); CPLXMLNode *node = CPLGetXMLNode(summary, "CoverageId"); - CPLString id; + std::string id; if (node) { id = CPLGetXMLValue(node, nullptr, ""); @@ -904,25 +887,23 @@ CPLErr WCSDataset110::ParseCapabilities(CPLXMLNode *Capabilities, return CE_Failure; } } - name = CPLURLAddKVP(name, "coverage", id); + name = CPLURLAddKVP(name, "coverage", id.c_str()); name = "WCS:" + name; metadata = CSLSetNameValue(metadata, key2, name); key2 = path3 + "DESC"; - CPLString desc; node = CPLGetXMLNode(summary, "Title"); if (node) { - desc = CPLGetXMLValue(node, nullptr, ""); + metadata = CSLSetNameValue(metadata, key2, + CPLGetXMLValue(node, nullptr, "")); } else { - desc = id; + metadata = CSLSetNameValue(metadata, key2, id.c_str()); } - metadata = CSLSetNameValue(metadata, key2, desc); - // todo: compose global bounding box from WGS84BoundingBox and // BoundingBox diff --git a/frmts/wcs/wcsdataset201.cpp b/frmts/wcs/wcsdataset201.cpp index 35b1a5556976..139c6a66faf5 100644 --- a/frmts/wcs/wcsdataset201.cpp +++ b/frmts/wcs/wcsdataset201.cpp @@ -683,7 +683,6 @@ int WCSDataset201::ParseRange(CPLXMLNode *coverage, bool in_band_range = false; unsigned int field_index = 1; - std::string field_name; std::vector nodata_array; for (CPLXMLNode *field = record->psChild; field != nullptr; @@ -773,10 +772,6 @@ int WCSDataset201::ParseRange(CPLXMLNode *coverage, *metadata, (key + "INTERVAL").c_str(), interval.c_str()); } - if (field_name == "") - { - field_name = fname; - } nodata_array.push_back(nodata); fields += 1; } diff --git a/frmts/wcs/wcsutils.cpp b/frmts/wcs/wcsutils.cpp index c433a29c6e0a..622de47fbf16 100644 --- a/frmts/wcs/wcsutils.cpp +++ b/frmts/wcs/wcsutils.cpp @@ -680,7 +680,7 @@ CPLErr AddEntryToCache(const std::string &cache, const std::string &url, VSIFWriteL(entry.c_str(), sizeof(char), entry.size(), f); VSIFCloseL(f); - filename = path; + filename = std::move(path); return CE_None; } diff --git a/frmts/zarr/zarr_group.cpp b/frmts/zarr/zarr_group.cpp index 34db203d769a..926463d1e7b8 100644 --- a/frmts/zarr/zarr_group.cpp +++ b/frmts/zarr/zarr_group.cpp @@ -526,7 +526,7 @@ bool ZarrGroupBase::Rename(const std::string &osNewName) m_poSharedResource->RenameZMetadataRecursive(m_osDirectoryName, osNewDirectoryName); - m_osDirectoryName = osNewDirectoryName; + m_osDirectoryName = std::move(osNewDirectoryName); BaseRename(osNewName); diff --git a/frmts/zarr/zarr_v2_array.cpp b/frmts/zarr/zarr_v2_array.cpp index cb5e6ac5c545..0b8e1f57159c 100644 --- a/frmts/zarr/zarr_v2_array.cpp +++ b/frmts/zarr/zarr_v2_array.cpp @@ -1564,7 +1564,7 @@ ZarrV2Group::LoadArray(const std::string &osArrayName, auto poNewRG = poRG->m_poParent.lock(); if (poNewRG == nullptr) break; - poRG = poNewRG; + poRG = std::move(poNewRG); } for (int i = 0; i < oShape.Size(); ++i) diff --git a/frmts/zarr/zarrdriver.cpp b/frmts/zarr/zarrdriver.cpp index 44f2130467c2..7919f7473f68 100644 --- a/frmts/zarr/zarrdriver.cpp +++ b/frmts/zarr/zarrdriver.cpp @@ -1127,13 +1127,13 @@ GDALDataset *ZarrDataset::Create(const char *pszName, int nXSize, int nYSize, pszArrayName ? pszArrayName : CPLGetBasename(pszName); if (poBandDim) { - const auto apoDims = + const std::vector> apoDims( bBandInterleave ? std::vector>{poBandDim, poDS->m_poDimY, poDS->m_poDimX} : std::vector>{ - poDS->m_poDimY, poDS->m_poDimX, poBandDim}; + poDS->m_poDimY, poDS->m_poDimX, poBandDim}); poDS->m_poSingleArray = poRG->CreateMDArray( pszNonNullArrayName, apoDims, GDALExtendedDataType::Create(eType), papszOptions); diff --git a/gcore/gdal_mdreader.cpp b/gcore/gdal_mdreader.cpp index 82308182fbd5..99d08f3204f2 100644 --- a/gcore/gdal_mdreader.cpp +++ b/gcore/gdal_mdreader.cpp @@ -1183,7 +1183,7 @@ CPLErr GDALWriteIMDFile(const char *pszFilename, char **papszMD) bOK &= VSIFPrintfL(fp, "BEGIN_GROUP = %s\n", osKeySection.c_str()) > 0; - osCurSection = osKeySection; + osCurSection = std::move(osKeySection); /* -------------------------------------------------------------------- */ diff --git a/gcore/gdal_rat.cpp b/gcore/gdal_rat.cpp index 42bd8222de32..af8edab87e48 100644 --- a/gcore/gdal_rat.cpp +++ b/gcore/gdal_rat.cpp @@ -2147,7 +2147,7 @@ void GDALDefaultRasterAttributeTable::RemoveStatistics() } } } - aoFields = aoNewFields; + aoFields = std::move(aoNewFields); } /************************************************************************/ diff --git a/gcore/gdaljp2structure.cpp b/gcore/gdaljp2structure.cpp index 7e8c3038ada1..bbc9e3055197 100644 --- a/gcore/gdaljp2structure.cpp +++ b/gcore/gdaljp2structure.cpp @@ -1241,8 +1241,8 @@ static CPLXMLNode *DumpJPK2CodeStream(CPLXMLNode *psBox, VSILFILE *fp, if (nRemainingMarkerSize >= 1) { v = *pabyMarkerDataIter; - const auto comment = - commentFunc ? commentFunc(v) : std::string(); + const std::string comment(commentFunc ? commentFunc(v) + : std::string()); AddField(psMarker, psLastChild, psDumpContext, name, *pabyMarkerDataIter, comment.empty() ? nullptr : comment.c_str()); diff --git a/gcore/gdalmultidim.cpp b/gcore/gdalmultidim.cpp index 02d7c647fb50..445bc0ff44bf 100644 --- a/gcore/gdalmultidim.cpp +++ b/gcore/gdalmultidim.cpp @@ -3251,7 +3251,7 @@ GByte *GDALRawResult::StealData() GDALRawResult GDALAttribute::ReadAsRaw() const { const auto nEltCount(GetTotalElementsCount()); - const auto dt(GetDataType()); + const auto &dt(GetDataType()); const auto nDTSize(dt.GetSize()); GByte *res = static_cast( VSI_MALLOC2_VERBOSE(static_cast(nEltCount), nDTSize)); @@ -9163,10 +9163,11 @@ GDALDatasetFromArray *GDALDatasetFromArray::Create( } } - oItem.osDefinition = osModDefinition; + oItem.osDefinition = std::move(osModDefinition); oItem.bDefinitionUsesPctForG = bDefinitionUsesPctForG; - aoBandParameterMetadataItems[iExtraDimIdx].emplace_back(oItem); + aoBandParameterMetadataItems[iExtraDimIdx].emplace_back( + std::move(oItem)); } } diff --git a/gcore/gdalmultidim_gridded.cpp b/gcore/gdalmultidim_gridded.cpp index 30cf3b1cd487..da4366c56618 100644 --- a/gcore/gdalmultidim_gridded.cpp +++ b/gcore/gdalmultidim_gridded.cpp @@ -263,7 +263,7 @@ bool GDALMDArrayGridded::IRead(const GUInt64 *arrayStartIdx, #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wnull-dereference" #endif - m_anLastStartIdx = anStartIdx; + m_anLastStartIdx = std::move(anStartIdx); #if defined(__GNUC__) && __GNUC__ >= 13 #pragma GCC diagnostic pop #endif diff --git a/gcore/gdalopeninfo.cpp b/gcore/gdalopeninfo.cpp index 582e53720595..86ceceaa4689 100644 --- a/gcore/gdalopeninfo.cpp +++ b/gcore/gdalopeninfo.cpp @@ -106,7 +106,7 @@ void GDALOpenInfoDeclareFileNotToOpen(const char *pszFilename, memcpy(fnto.pabyHeader, pabyHeader, nHeaderBytes); fnto.pabyHeader[nHeaderBytes] = 0; fnto.nHeaderBytes = nHeaderBytes; - (*pMapFNTO)[pszFilename] = fnto; + (*pMapFNTO)[pszFilename] = std::move(fnto); } } diff --git a/gcore/gdalpythondriverloader.cpp b/gcore/gdalpythondriverloader.cpp index 3bd660358adb..3079a5efae30 100644 --- a/gcore/gdalpythondriverloader.cpp +++ b/gcore/gdalpythondriverloader.cpp @@ -1884,7 +1884,7 @@ static void LoadPythonDriver(const char *pszFilename) osValue.resize(osValue.size() - 1); if (EQUAL(osKey, "NAME")) { - osPluginName = osValue; + osPluginName = std::move(osValue); } else if (EQUAL(osKey, "SUPPORTED_API_VERSION")) { diff --git a/gcore/mdreader/reader_alos.cpp b/gcore/mdreader/reader_alos.cpp index c80e096cd139..56b7f5e39ef9 100644 --- a/gcore/mdreader/reader_alos.cpp +++ b/gcore/mdreader/reader_alos.cpp @@ -54,14 +54,14 @@ GDALMDReaderALOS::GDALMDReaderALOS(const char *pszPath, CPLFormFilename(osDirName, "summary", ".txt"); if (CPLCheckForFile(&osIMDSourceFilename[0], papszSiblingFiles)) { - m_osIMDSourceFilename = osIMDSourceFilename; + m_osIMDSourceFilename = std::move(osIMDSourceFilename); } else { osIMDSourceFilename = CPLFormFilename(osDirName, "SUMMARY", ".TXT"); if (CPLCheckForFile(&osIMDSourceFilename[0], papszSiblingFiles)) { - m_osIMDSourceFilename = osIMDSourceFilename; + m_osIMDSourceFilename = std::move(osIMDSourceFilename); } } @@ -73,7 +73,7 @@ GDALMDReaderALOS::GDALMDReaderALOS(const char *pszPath, osDirName, CPLSPrintf("HDR%s", osBaseName + 6), "txt"); if (CPLCheckForFile(&osHDRFileName[0], papszSiblingFiles)) { - m_osHDRSourceFilename = osHDRFileName; + m_osHDRSourceFilename = std::move(osHDRFileName); } else { @@ -81,7 +81,7 @@ GDALMDReaderALOS::GDALMDReaderALOS(const char *pszPath, osDirName, CPLSPrintf("HDR%s", osBaseName + 6), "TXT"); if (CPLCheckForFile(&osHDRFileName[0], papszSiblingFiles)) { - m_osHDRSourceFilename = osHDRFileName; + m_osHDRSourceFilename = std::move(osHDRFileName); } } } @@ -93,7 +93,7 @@ GDALMDReaderALOS::GDALMDReaderALOS(const char *pszPath, osDirName, CPLSPrintf("HDR%s", osBaseName + 3), "txt"); if (CPLCheckForFile(&osHDRFileName[0], papszSiblingFiles)) { - m_osHDRSourceFilename = osHDRFileName; + m_osHDRSourceFilename = std::move(osHDRFileName); } else { @@ -101,7 +101,7 @@ GDALMDReaderALOS::GDALMDReaderALOS(const char *pszPath, osDirName, CPLSPrintf("HDR%s", osBaseName + 3), "TXT"); if (CPLCheckForFile(&osHDRFileName[0], papszSiblingFiles)) { - m_osHDRSourceFilename = osHDRFileName; + m_osHDRSourceFilename = std::move(osHDRFileName); } } } @@ -113,7 +113,7 @@ GDALMDReaderALOS::GDALMDReaderALOS(const char *pszPath, osDirName, CPLSPrintf("RPC%s", osBaseName + 6), "txt"); if (CPLCheckForFile(&osRPCFileName[0], papszSiblingFiles)) { - m_osRPBSourceFilename = osRPCFileName; + m_osRPBSourceFilename = std::move(osRPCFileName); } else { @@ -121,7 +121,7 @@ GDALMDReaderALOS::GDALMDReaderALOS(const char *pszPath, osDirName, CPLSPrintf("RPC%s", osBaseName + 6), "TXT"); if (CPLCheckForFile(&osRPCFileName[0], papszSiblingFiles)) { - m_osRPBSourceFilename = osRPCFileName; + m_osRPBSourceFilename = std::move(osRPCFileName); } } } @@ -133,7 +133,7 @@ GDALMDReaderALOS::GDALMDReaderALOS(const char *pszPath, osDirName, CPLSPrintf("RPC%s", osBaseName + 3), "txt"); if (CPLCheckForFile(&osRPCFileName[0], papszSiblingFiles)) { - m_osRPBSourceFilename = osRPCFileName; + m_osRPBSourceFilename = std::move(osRPCFileName); } else { @@ -141,7 +141,7 @@ GDALMDReaderALOS::GDALMDReaderALOS(const char *pszPath, osDirName, CPLSPrintf("RPC%s", osBaseName + 3), "TXT"); if (CPLCheckForFile(&osRPCFileName[0], papszSiblingFiles)) { - m_osRPBSourceFilename = osRPCFileName; + m_osRPBSourceFilename = std::move(osRPCFileName); } } } diff --git a/gcore/mdreader/reader_geo_eye.cpp b/gcore/mdreader/reader_geo_eye.cpp index ddd8a2829f4a..8f224b887b3e 100644 --- a/gcore/mdreader/reader_geo_eye.cpp +++ b/gcore/mdreader/reader_geo_eye.cpp @@ -63,11 +63,11 @@ GDALMDReaderGeoEye::GDALMDReaderGeoEye(const char *pszPath, osRadixMetadataName.resize(i); // form metadata file name - CPLString osIMDSourceFilename = CPLFormFilename( + std::string osIMDSourceFilename = CPLFormFilename( osDirName, (osRadixMetadataName + "_metadata.txt").c_str(), nullptr); if (CPLCheckForFile(&osIMDSourceFilename[0], papszSiblingFiles)) { - m_osIMDSourceFilename = osIMDSourceFilename; + m_osIMDSourceFilename = std::move(osIMDSourceFilename); } else { @@ -76,17 +76,17 @@ GDALMDReaderGeoEye::GDALMDReaderGeoEye(const char *pszPath, nullptr); if (CPLCheckForFile(&osIMDSourceFilename[0], papszSiblingFiles)) { - m_osIMDSourceFilename = osIMDSourceFilename; + m_osIMDSourceFilename = std::move(osIMDSourceFilename); } } // get _rpc.txt file - CPLString osRPBSourceFilename = + std::string osRPBSourceFilename = CPLFormFilename(osDirName, (osBaseName + "_rpc").c_str(), "txt"); if (CPLCheckForFile(&osRPBSourceFilename[0], papszSiblingFiles)) { - m_osRPBSourceFilename = osRPBSourceFilename; + m_osRPBSourceFilename = std::move(osRPBSourceFilename); } else { @@ -94,7 +94,7 @@ GDALMDReaderGeoEye::GDALMDReaderGeoEye(const char *pszPath, CPLFormFilename(osDirName, (osBaseName + "_RPC").c_str(), "TXT"); if (CPLCheckForFile(&osRPBSourceFilename[0], papszSiblingFiles)) { - m_osRPBSourceFilename = osRPBSourceFilename; + m_osRPBSourceFilename = std::move(osRPBSourceFilename); } } diff --git a/gcore/mdreader/reader_rapid_eye.cpp b/gcore/mdreader/reader_rapid_eye.cpp index fae952c7d828..b6178a42fefc 100644 --- a/gcore/mdreader/reader_rapid_eye.cpp +++ b/gcore/mdreader/reader_rapid_eye.cpp @@ -47,11 +47,11 @@ GDALMDReaderRapidEye::GDALMDReaderRapidEye(const char *pszPath, const char *pszDirName = CPLGetDirname(pszPath); const char *pszBaseName = CPLGetBasename(pszPath); - CPLString osIMDSourceFilename = CPLFormFilename( + std::string osIMDSourceFilename = CPLFormFilename( pszDirName, CPLSPrintf("%s_metadata", pszBaseName), "xml"); if (CPLCheckForFile(&osIMDSourceFilename[0], papszSiblingFiles)) { - m_osXMLSourceFilename = osIMDSourceFilename; + m_osXMLSourceFilename = std::move(osIMDSourceFilename); } else { @@ -59,7 +59,7 @@ GDALMDReaderRapidEye::GDALMDReaderRapidEye(const char *pszPath, pszDirName, CPLSPrintf("%s_METADATA", pszBaseName), "XML"); if (CPLCheckForFile(&osIMDSourceFilename[0], papszSiblingFiles)) { - m_osXMLSourceFilename = osIMDSourceFilename; + m_osXMLSourceFilename = std::move(osIMDSourceFilename); } } diff --git a/gnm/gnm_frmts/db/gnmdbnetwork.cpp b/gnm/gnm_frmts/db/gnmdbnetwork.cpp index f36d4b6979b8..7ad9ed5b1ca6 100644 --- a/gnm/gnm_frmts/db/gnmdbnetwork.cpp +++ b/gnm/gnm_frmts/db/gnmdbnetwork.cpp @@ -144,7 +144,7 @@ CPLErr GNMDatabaseNetwork::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/ogr/ogr_geocoding.cpp b/ogr/ogr_geocoding.cpp index 6c3283a26a6e..871372157381 100644 --- a/ogr/ogr_geocoding.cpp +++ b/ogr/ogr_geocoding.cpp @@ -1236,8 +1236,11 @@ static OGRLayerH OGRGeocodeBuildLayer(const char *pszContent, /************************************************************************/ static OGRLayerH OGRGeocodeCommon(OGRGeocodingSessionH hSession, - std::string osURL, char **papszOptions) + const std::string &osURLIn, + char **papszOptions) { + std::string osURL(osURLIn); + // Only documented to work with OSM Nominatim. if (hSession->pszLanguage != nullptr) { diff --git a/ogr/ogr_xerces.cpp b/ogr/ogr_xerces.cpp index 2c21e0a1a9dc..2eca185d7ee3 100644 --- a/ogr/ogr_xerces.cpp +++ b/ogr/ogr_xerces.cpp @@ -305,7 +305,7 @@ void OGRStartXercesLimitsForThisThread(size_t nMaxMemAlloc, limitation.timeOut = dfTimeoutSecond; if (pszMsgTimeout) limitation.osMsgTimeout = pszMsgTimeout; - (*gpoMapThreadTimeout)[CPLGetPID()] = limitation; + (*gpoMapThreadTimeout)[CPLGetPID()] = std::move(limitation); } /************************************************************************/ diff --git a/ogr/ogrcurve.cpp b/ogr/ogrcurve.cpp index 784e7d1cc0dd..fa1d2189e381 100644 --- a/ogr/ogrcurve.cpp +++ b/ogr/ogrcurve.cpp @@ -815,7 +815,7 @@ int OGRCurve::isClockwise() const for (int i = 1; i < nPointCount - 1; i++) { ++oIter; - auto oPointNext = *oIter; + const auto &oPointNext = *oIter; dfSum += oPointCur.getX() * (oPointNext.getY() - oPointBefore.getY()); oPointBefore = oPointCur; oPointCur = oPointNext; diff --git a/ogr/ogrsf_frmts/arrow/ogrfeatherlayer.cpp b/ogr/ogrsf_frmts/arrow/ogrfeatherlayer.cpp index f503e2af2e4e..44fb3d7f934f 100644 --- a/ogr/ogrsf_frmts/arrow/ogrfeatherlayer.cpp +++ b/ogr/ogrsf_frmts/arrow/ogrfeatherlayer.cpp @@ -205,7 +205,7 @@ void OGRFeatherLayer::EstablishFeatureDefn() oJSONDef = oIter->second; auto osEncoding = oJSONDef.GetString("encoding"); if (osEncoding.empty() && !osExtensionName.empty()) - osEncoding = osExtensionName; + osEncoding = std::move(osExtensionName); OGRwkbGeometryType eGeomType = wkbUnknown; auto eGeomEncoding = OGRArrowGeomEncoding::WKB; diff --git a/ogr/ogrsf_frmts/arrow_common/ograrrowwriterlayer.hpp b/ogr/ogrsf_frmts/arrow_common/ograrrowwriterlayer.hpp index 91d2469d40b7..3be97c7aa576 100644 --- a/ogr/ogrsf_frmts/arrow_common/ograrrowwriterlayer.hpp +++ b/ogr/ogrsf_frmts/arrow_common/ograrrowwriterlayer.hpp @@ -2129,7 +2129,8 @@ inline bool OGRArrowWriterLayer::WriteArrowBatchInternal( } } - auto poRecordBatchResult = arrow::ImportRecordBatch(array, poSchema); + auto poRecordBatchResult = + arrow::ImportRecordBatch(array, std::move(poSchema)); if (!poRecordBatchResult.ok()) { CPLError(CE_Failure, CPLE_AppDefined, diff --git a/ogr/ogrsf_frmts/dxf/ogrdxflayer.cpp b/ogr/ogrsf_frmts/dxf/ogrdxflayer.cpp index 851cea06cef6..6d7962ccc5ac 100644 --- a/ogr/ogrsf_frmts/dxf/ogrdxflayer.cpp +++ b/ogr/ogrsf_frmts/dxf/ogrdxflayer.cpp @@ -564,7 +564,7 @@ OGRDXFFeature *OGRDXFLayer::TranslateMTEXT() /* -------------------------------------------------------------------- */ if (strchr(osText, '"') != nullptr) { - CPLString osEscaped; + std::string osEscaped; for (size_t iC = 0; iC < osText.size(); iC++) { @@ -573,7 +573,7 @@ OGRDXFFeature *OGRDXFLayer::TranslateMTEXT() else osEscaped += osText[iC]; } - osText = osEscaped; + osText = std::move(osEscaped); } /* -------------------------------------------------------------------- */ diff --git a/ogr/ogrsf_frmts/dxf/ogrdxfwriterlayer.cpp b/ogr/ogrsf_frmts/dxf/ogrdxfwriterlayer.cpp index d483a62143fc..95fdad4b0d8e 100644 --- a/ogr/ogrsf_frmts/dxf/ogrdxfwriterlayer.cpp +++ b/ogr/ogrsf_frmts/dxf/ogrdxfwriterlayer.cpp @@ -605,7 +605,7 @@ OGRErr OGRDXFWriterLayer::WriteTEXT(OGRFeature *poFeature) osStyleName.Printf("AutoTextStyle-%d", nNextAutoID++); } while (poDS->oHeaderDS.TextStyleExists(osStyleName)); - oNewTextStyles[osStyleName] = oTextStyleDef; + oNewTextStyles[osStyleName] = std::move(oTextStyleDef); } WriteValue(7, osStyleName); diff --git a/ogr/ogrsf_frmts/edigeo/ogredigeodatasource.cpp b/ogr/ogrsf_frmts/edigeo/ogredigeodatasource.cpp index f0fbd612998f..9931c22166b7 100644 --- a/ogr/ogrsf_frmts/edigeo/ogredigeodatasource.cpp +++ b/ogr/ogrsf_frmts/edigeo/ogredigeodatasource.cpp @@ -458,7 +458,7 @@ int OGREDIGEODataSource::ReadSCD() /*CPLDebug("EDIGEO", "Attribute %s = %s, %d", osRID.c_str(), osNameRID.c_str(), nWidth);*/ - mapAttributesSCD[osRID] = attDesc; + mapAttributesSCD[osRID] = std::move(attDesc); } } } diff --git a/ogr/ogrsf_frmts/elastic/ogrelasticaggregationlayer.cpp b/ogr/ogrsf_frmts/elastic/ogrelasticaggregationlayer.cpp index 5e141442ed54..b9d70f3e9e01 100644 --- a/ogr/ogrsf_frmts/elastic/ogrelasticaggregationlayer.cpp +++ b/ogr/ogrsf_frmts/elastic/ogrelasticaggregationlayer.cpp @@ -138,7 +138,7 @@ OGRElasticAggregationLayer::Build(OGRElasticDataSource *poDS, auto poLayer = std::unique_ptr( new OGRElasticAggregationLayer(poDS)); poLayer->m_osIndexName = osIndex; - poLayer->m_osGeometryField = osGeometryField; + poLayer->m_osGeometryField = std::move(osGeometryField); // Parse geohash_grid options auto oGeohashGrid = oRoot["geohash_grid"]; diff --git a/ogr/ogrsf_frmts/filegdb/FGdbDatasource.cpp b/ogr/ogrsf_frmts/filegdb/FGdbDatasource.cpp index c1aa19cc2e39..02294f76c724 100644 --- a/ogr/ogrsf_frmts/filegdb/FGdbDatasource.cpp +++ b/ogr/ogrsf_frmts/filegdb/FGdbDatasource.cpp @@ -592,8 +592,8 @@ bool FGdbDataSource::LoadLayers(const std::wstring &root) poFeature->GetFieldAsString(iDefinition)); if (poRelationship) { - const auto relationshipName = - poRelationship->GetName(); + const std::string relationshipName( + poRelationship->GetName()); m_osMapRelationships[relationshipName] = std::move(poRelationship); } @@ -997,7 +997,7 @@ FGdbDataSource::GetFieldDomain(const std::string &name) const auto poDomain = ParseXMLFieldDomainDef(domainDef); if (!poDomain) return nullptr; - const auto domainName = poDomain->GetName(); + const std::string domainName(poDomain->GetName()); m_oMapFieldDomains[domainName] = std::move(poDomain); return GDALDataset::GetFieldDomain(name); } @@ -1032,7 +1032,7 @@ std::vector FGdbDataSource::GetFieldDomainNames(CSLConstList) const bool FGdbDataSource::AddFieldDomain(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/flatgeobuf/packedrtree.cpp b/ogr/ogrsf_frmts/flatgeobuf/packedrtree.cpp index 60074208495c..9be922abbdcb 100644 --- a/ogr/ogrsf_frmts/flatgeobuf/packedrtree.cpp +++ b/ogr/ogrsf_frmts/flatgeobuf/packedrtree.cpp @@ -200,15 +200,16 @@ void hilbertSort(std::vector &items) NodeItem calcExtent(const std::vector> &items) { - return std::accumulate(items.begin(), items.end(), NodeItem::create(0), - [](NodeItem a, const std::shared_ptr &b) - { return a.expand(b->nodeItem); }); + return std::accumulate( + items.begin(), items.end(), NodeItem::create(0), + [](NodeItem a, const std::shared_ptr &b) -> NodeItem + { return a.expand(b->nodeItem); }); } NodeItem calcExtent(const std::vector &nodes) { return std::accumulate(nodes.begin(), nodes.end(), NodeItem::create(0), - [](NodeItem a, const NodeItem &b) + [](NodeItem a, const NodeItem &b) -> NodeItem { return a.expand(b); }); } @@ -350,7 +351,7 @@ PackedRTree::search(double minX, double minY, double maxX, double maxY) const // search through child nodes for (uint64_t pos = nodeIndex; pos < end; pos++) { - auto nodeItem = _nodeItems[static_cast(pos)]; + const auto &nodeItem = _nodeItems[static_cast(pos)]; if (!n.intersects(nodeItem)) continue; if (isLeafNode) @@ -403,7 +404,7 @@ std::vector PackedRTree::streamSearch( for (uint64_t pos = nodeIndex; pos < end; pos++) { uint64_t nodePos = pos - nodeIndex; - auto nodeItem = nodeItems[static_cast(nodePos)]; + const auto &nodeItem = nodeItems[static_cast(nodePos)]; if (!item.intersects(nodeItem)) continue; if (isLeafNode) diff --git a/ogr/ogrsf_frmts/flatgeobuf/packedrtree.h b/ogr/ogrsf_frmts/flatgeobuf/packedrtree.h index 26f72d4738d1..aef929bbc3a2 100644 --- a/ogr/ogrsf_frmts/flatgeobuf/packedrtree.h +++ b/ogr/ogrsf_frmts/flatgeobuf/packedrtree.h @@ -91,7 +91,7 @@ template NodeItem calcExtent(const std::deque &items) { return std::accumulate(items.begin(), items.end(), NodeItem::create(0), - [](NodeItem a, const ITEM_TYPE &b) + [](NodeItem a, const ITEM_TYPE &b) -> NodeItem { return a.expand(b.nodeItem); }); } diff --git a/ogr/ogrsf_frmts/geojson/directedacyclicgraph.hpp b/ogr/ogrsf_frmts/geojson/directedacyclicgraph.hpp index adc76ea7bbe3..7ef3fa40b0ea 100644 --- a/ogr/ogrsf_frmts/geojson/directedacyclicgraph.hpp +++ b/ogr/ogrsf_frmts/geojson/directedacyclicgraph.hpp @@ -245,7 +245,7 @@ std::vector DirectedAcyclicGraph::getTopologicalOrdering() if (iter != outgoingNodes.end()) { // Need to take a copy as we remove edges during iteration - const auto myOutgoingNodes = iter->second; + const std::set myOutgoingNodes = iter->second; for (const T &m : myOutgoingNodes) { const char *retRemoveEdge = removeEdge(n, m); diff --git a/ogr/ogrsf_frmts/gmlas/ogrgmlaslayer.cpp b/ogr/ogrsf_frmts/gmlas/ogrgmlaslayer.cpp index 695aa99fb7b6..70479a4ed6a8 100644 --- a/ogr/ogrsf_frmts/gmlas/ogrgmlaslayer.cpp +++ b/ogr/ogrsf_frmts/gmlas/ogrgmlaslayer.cpp @@ -1051,7 +1051,7 @@ bool OGRGMLASLayer::RemoveField(int nIdx) else if (oIter.first > nIdx) oMapOGRFieldIdxtoFCFieldIdx[oIter.first - 1] = oIter.second; } - m_oMapOGRFieldIdxtoFCFieldIdx = oMapOGRFieldIdxtoFCFieldIdx; + m_oMapOGRFieldIdxtoFCFieldIdx = std::move(oMapOGRFieldIdxtoFCFieldIdx); } OGRLayer *poFieldsMetadataLayer = m_poDS->GetFieldsMetadataLayer(); diff --git a/ogr/ogrsf_frmts/gmlas/ogrgmlasschemaanalyzer.cpp b/ogr/ogrsf_frmts/gmlas/ogrgmlasschemaanalyzer.cpp index f9f1b15a8db7..0d76b6286964 100644 --- a/ogr/ogrsf_frmts/gmlas/ogrgmlasschemaanalyzer.cpp +++ b/ogr/ogrsf_frmts/gmlas/ogrgmlasschemaanalyzer.cpp @@ -105,10 +105,10 @@ void GMLASPrefixMappingHander::startElement(const XMLCh *const uri, if (osURI == szXS_URI && osLocalname == "schema") { bool bIsGML = false; - CPLString osVersion; + std::string osVersion; for (unsigned int i = 0; i < attrs.getLength(); i++) { - CPLString osAttrLocalName(transcode(attrs.getLocalName(i))); + const std::string osAttrLocalName(transcode(attrs.getLocalName(i))); if (osAttrLocalName == "targetNamespace") { bIsGML = transcode(attrs.getValue(i)) == szGML_URI; @@ -120,7 +120,7 @@ void GMLASPrefixMappingHander::startElement(const XMLCh *const uri, } if (bIsGML && !osVersion.empty()) { - m_osGMLVersionFound = osVersion; + m_osGMLVersionFound = std::move(osVersion); } } } @@ -2134,7 +2134,7 @@ bool GMLASSchemaAnalyzer::FindElementsWithMustBeToLevel( { if (!apoChildrenElements.empty()) { - apoImplEltList = apoChildrenElements; + apoImplEltList = std::move(apoChildrenElements); } else if (!poElt->getAbstract()) { diff --git a/ogr/ogrsf_frmts/gmt/ogrgmtlayer.cpp b/ogr/ogrsf_frmts/gmt/ogrgmtlayer.cpp index d40d23faac4f..5861161138ee 100644 --- a/ogr/ogrsf_frmts/gmt/ogrgmtlayer.cpp +++ b/ogr/ogrsf_frmts/gmt/ogrgmtlayer.cpp @@ -99,23 +99,23 @@ OGRGmtLayer::OGRGmtLayer(const char *pszFilename, VSILFILE *fp, papszKeyedValues[iKey][1] != 0 && papszKeyedValues[iKey][2] != 0) { - CPLString osArg = papszKeyedValues[iKey] + 2; + std::string osArg = papszKeyedValues[iKey] + 2; if (osArg[0] == '"' && osArg.size() >= 2 && osArg.back() == '"') { osArg = osArg.substr(1, osArg.length() - 2); char *pszArg = CPLUnescapeString( - osArg, nullptr, CPLES_BackslashQuotable); + osArg.c_str(), nullptr, CPLES_BackslashQuotable); osArg = pszArg; CPLFree(pszArg); } if (papszKeyedValues[iKey][1] == 'e') - osEPSG = osArg; + osEPSG = std::move(osArg); if (papszKeyedValues[iKey][1] == 'p') - osProj4 = osArg; + osProj4 = std::move(osArg); if (papszKeyedValues[iKey][1] == 'w') - osWKT = osArg; + osWKT = std::move(osArg); } } diff --git a/ogr/ogrsf_frmts/gpkg/ogrgeopackagedatasource.cpp b/ogr/ogrsf_frmts/gpkg/ogrgeopackagedatasource.cpp index 17ad47e3135a..ec438fb63d20 100644 --- a/ogr/ogrsf_frmts/gpkg/ogrgeopackagedatasource.cpp +++ b/ogr/ogrsf_frmts/gpkg/ogrgeopackagedatasource.cpp @@ -211,9 +211,10 @@ OGRErr GDALGeoPackageDataset::SetApplicationAndUserVersionId() { CPLAssert(hDB != nullptr); - const auto osPragma = CPLString().Printf("PRAGMA application_id = %u;" - "PRAGMA user_version = %u", - m_nApplicationId, m_nUserVersion); + const CPLString osPragma(CPLString().Printf("PRAGMA application_id = %u;" + "PRAGMA user_version = %u", + m_nApplicationId, + m_nUserVersion)); return SQLCommand(hDB, osPragma.c_str()); } @@ -7436,9 +7437,9 @@ OGRLayer *GDALGeoPackageDataset::ExecuteSQL(const char *pszSQLCommand, /* Create layer. */ /* -------------------------------------------------------------------- */ - CPLString osSQL = osSQLCommand; OGRLayer *poLayer = new OGRGeoPackageSelectLayer( - this, osSQL, hSQLStmt, bUseStatementForGetNextFeature, bEmptyLayer); + this, osSQLCommand, hSQLStmt, bUseStatementForGetNextFeature, + bEmptyLayer); if (poSpatialFilter != nullptr && poLayer->GetLayerDefn()->GetGeomFieldCount() > 0) @@ -9490,7 +9491,7 @@ GDALGeoPackageDataset::GetFieldDomain(const std::string &name) const bool GDALGeoPackageDataset::AddFieldDomain( std::unique_ptr &&domain, std::string &failureReason) { - const auto domainName = domain->GetName(); + const std::string domainName(domain->GetName()); if (!GetUpdate()) { CPLError(CE_Failure, CPLE_NotSupported, diff --git a/ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp b/ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp index 9706e88f6bc3..05ab9461a6eb 100644 --- a/ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp +++ b/ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp @@ -5301,7 +5301,7 @@ OGRErr OGRGeoPackageTableLayer::Rename(const char *pszDstTableName) if (bHasSpatialIndex) { m_poDS->RemoveTableFromSQLiteMasterCache(m_osRTreeName); - m_osRTreeName = osRTreeNameNew; + m_osRTreeName = std::move(osRTreeNameNew); } } } diff --git a/ogr/ogrsf_frmts/hana/ogrhanadatasource.cpp b/ogr/ogrsf_frmts/hana/ogrhanadatasource.cpp index 0bf4bc2774cc..efc8e8fddf6e 100644 --- a/ogr/ogrsf_frmts/hana/ogrhanadatasource.cpp +++ b/ogr/ogrsf_frmts/hana/ogrhanadatasource.cpp @@ -1125,15 +1125,15 @@ OGRErr OGRHanaDataSource::GetQueryColumns( detectGeometryType_); geometryColumnDesc.isNullable = rsmd->isNullable(clmIndex); - columnDescriptions.push_back( - {true, AttributeColumnDescription(), geometryColumnDesc}); + columnDescriptions.push_back({true, AttributeColumnDescription(), + std::move(geometryColumnDesc)}); } else { AttributeColumnDescription attributeColumnDesc; - attributeColumnDesc.name = columnName; + attributeColumnDesc.name = std::move(columnName); attributeColumnDesc.type = dataType; - attributeColumnDesc.typeName = typeName; + attributeColumnDesc.typeName = std::move(typeName); attributeColumnDesc.isArray = isArray; attributeColumnDesc.isNullable = rsmd->isNullable(clmIndex); attributeColumnDesc.isAutoIncrement = @@ -1142,10 +1142,10 @@ OGRErr OGRHanaDataSource::GetQueryColumns( static_cast(rsmd->getColumnLength(clmIndex)); attributeColumnDesc.precision = rsmd->getPrecision(clmIndex); attributeColumnDesc.scale = rsmd->getScale(clmIndex); - attributeColumnDesc.defaultValue = defaultValue; + attributeColumnDesc.defaultValue = std::move(defaultValue); - columnDescriptions.push_back( - {false, attributeColumnDesc, GeometryColumnDescription()}); + columnDescriptions.push_back({false, std::move(attributeColumnDesc), + GeometryColumnDescription()}); } } diff --git a/ogr/ogrsf_frmts/hana/ogrhanafeaturereader.cpp b/ogr/ogrsf_frmts/hana/ogrhanafeaturereader.cpp index afad2dd16d7a..5283f5aa79cc 100644 --- a/ogr/ogrsf_frmts/hana/ogrhanafeaturereader.cpp +++ b/ogr/ogrsf_frmts/hana/ogrhanafeaturereader.cpp @@ -469,7 +469,7 @@ odbc::String OGRHanaFeatureReader::GetFieldAsRealArray(int fieldIndex) const feature_.GetFieldAsDoubleList(fieldIndex, &numElements); return CreateStringFromValues( values, numElements, - [](double value) + [](double value) -> std::string { return std::isnan(value) ? "NULL" diff --git a/ogr/ogrsf_frmts/jsonfg/ogrjsonfgreader.cpp b/ogr/ogrsf_frmts/jsonfg/ogrjsonfgreader.cpp index 7782ec11defd..5c38f0302436 100644 --- a/ogr/ogrsf_frmts/jsonfg/ogrjsonfgreader.cpp +++ b/ogr/ogrsf_frmts/jsonfg/ogrjsonfgreader.cpp @@ -847,7 +847,7 @@ bool OGRJSONFGReader::GenerateLayerDefnFromFeature(json_object *poObj) if (!poContext->bHasCoordRefSysAtFeatureLevel) { poContext->bHasCoordRefSysAtFeatureLevel = true; - poContext->osCoordRefSysAtFeatureLevel = osVal; + poContext->osCoordRefSysAtFeatureLevel = std::move(osVal); poContext->poCRSAtFeatureLevel = OGRJSONFGReadCoordRefSys(poCoordRefSys); if (poContext->poCRSAtFeatureLevel) diff --git a/ogr/ogrsf_frmts/libkml/ogrlibkmldatasource.cpp b/ogr/ogrsf_frmts/libkml/ogrlibkmldatasource.cpp index 3b49debf8283..a1719078d960 100644 --- a/ogr/ogrsf_frmts/libkml/ogrlibkmldatasource.cpp +++ b/ogr/ogrsf_frmts/libkml/ogrlibkmldatasource.cpp @@ -455,7 +455,7 @@ bool OGRLIBKMLDataSource::WriteKmz() if (!poKmlDocument->get_schema_array_size() && poKmlSchema && poKmlSchema->get_simplefield_array_size()) { - poKmlDocument->add_schema(poKmlSchema); + poKmlDocument->add_schema(std::move(poKmlSchema)); } papoLayers[iLayer]->Finalize(poKmlDocument); @@ -585,7 +585,7 @@ bool OGRLIBKMLDataSource::WriteDir() if (!poKmlDocument->get_schema_array_size() && poKmlSchema && poKmlSchema->get_simplefield_array_size()) { - poKmlDocument->add_schema(poKmlSchema); + poKmlDocument->add_schema(std::move(poKmlSchema)); } papoLayers[iLayer]->Finalize(poKmlDocument); @@ -781,7 +781,7 @@ SchemaPtr OGRLIBKMLDataSource::FindSchema(const char *pszSchemaUrl) { if (EQUAL(pszID, poKmlSchema->get_id().c_str())) { - poKmlSchemaResult = poKmlSchema; + poKmlSchemaResult = std::move(poKmlSchema); break; } } @@ -790,7 +790,7 @@ SchemaPtr OGRLIBKMLDataSource::FindSchema(const char *pszSchemaUrl) { if (EQUAL(pszSchemaName, poKmlSchema->get_name().c_str())) { - poKmlSchemaResult = poKmlSchema; + poKmlSchemaResult = std::move(poKmlSchema); break; } } @@ -1283,8 +1283,8 @@ int OGRLIBKMLDataSource::OpenKmz(const char *pszFilename, int bUpdateIn) * write it *****/ if (nLinks) { - m_poKmlDocKml = poKmlContainer; - m_poKmlDocKmlRoot = poKmlDocKmlRoot; + m_poKmlDocKml = std::move(poKmlContainer); + m_poKmlDocKmlRoot = std::move(poKmlDocKmlRoot); } /***** if the doc.kml has no links treat it as a normal kml file *****/ else diff --git a/ogr/ogrsf_frmts/libkml/ogrlibkmlstyle.cpp b/ogr/ogrsf_frmts/libkml/ogrlibkmlstyle.cpp index 5e3daafb1ecb..699719a2f128 100644 --- a/ogr/ogrsf_frmts/libkml/ogrlibkmlstyle.cpp +++ b/ogr/ogrsf_frmts/libkml/ogrlibkmlstyle.cpp @@ -760,7 +760,7 @@ static ContainerPtr MyGetContainerFromRoot(KmlFactory *poKmlFactory, } else if (poKmlRoot->IsA(kmldom::Type_Container)) { - poKmlContainer = AsContainer(poKmlRoot); + poKmlContainer = AsContainer(std::move(poKmlRoot)); } } diff --git a/ogr/ogrsf_frmts/mvt/ogrmvtdataset.cpp b/ogr/ogrsf_frmts/mvt/ogrmvtdataset.cpp index c29ecd812ba3..c4048fea586b 100644 --- a/ogr/ogrsf_frmts/mvt/ogrmvtdataset.cpp +++ b/ogr/ogrsf_frmts/mvt/ogrmvtdataset.cpp @@ -2773,7 +2773,7 @@ GDALDataset *OGRMVTDataset::OpenDirectory(GDALOpenInfo *poOpenInfo) OGRMVTDataset *poDS = new OGRMVTDataset(nullptr); - CPLString osMetadataMemFilename = + const CPLString osMetadataMemFilename = CPLSPrintf("/vsimem/%p_metadata.json", poDS); if (!LoadMetadata(osMetadataFile, osMetadataContent, oVectorLayers, oTileStatLayers, oBounds, poDS->m_poSRS, @@ -3339,7 +3339,7 @@ class OGRMVTWriterDataset final : public GDALDataset const MVTTileLayerValue &oValue); void EncodeFeature(const void *pabyBlob, int nBlobSize, - std::shared_ptr poTargetLayer, + std::shared_ptr &poTargetLayer, std::map &oMapKeyToIdx, std::map &oMapValueToIdx, MVTLayerProperties *poLayerProperties, GUInt32 nExtent, @@ -4719,7 +4719,7 @@ GetReducedPrecisionGeometry(MVTTileLayerFeature::GeomType eGeomType, void OGRMVTWriterDataset::EncodeFeature( const void *pabyBlob, int nBlobSize, - std::shared_ptr poTargetLayer, + std::shared_ptr &poTargetLayer, std::map &oMapKeyToIdx, std::map &oMapValueToIdx, MVTLayerProperties *poLayerProperties, GUInt32 nExtent, @@ -5030,7 +5030,7 @@ std::string OGRMVTWriterDataset::EncodeTile( poTargetLayer->setName(pszLayerName); poTargetLayer->setVersion(m_nMVTVersion); poTargetLayer->setExtent(nExtent); - oMapLayerNameToTargetLayer[pszLayerName] = props; + oMapLayerNameToTargetLayer[pszLayerName] = std::move(props); poMapKeyToIdx = &oMapLayerNameToTargetLayer[pszLayerName].m_oMapKeyToIdx; poMapValueToIdx = @@ -5859,9 +5859,9 @@ OGRLayer *OGRMVTWriterDataset::ICreateLayer(const char *pszLayerName, CPLString osDescription; if (oObj.IsValid()) { - CPLString osTargetName = oObj.GetString("target_name"); + std::string osTargetName = oObj.GetString("target_name"); if (!osTargetName.empty()) - poLayer->m_osTargetName = osTargetName; + poLayer->m_osTargetName = std::move(osTargetName); int nMinZoom = oObj.GetInteger("minzoom", -1); if (nMinZoom >= 0) poLayer->m_nMinZoom = nMinZoom; @@ -5885,7 +5885,8 @@ OGRLayer *OGRMVTWriterDataset::ICreateLayer(const char *pszLayerName, osDescription = CSLFetchNameValueDef(papszOptions, "DESCRIPTION", osDescription); if (!osDescription.empty()) - m_oMapLayerNameToDesc[poLayer->m_osTargetName] = osDescription; + m_oMapLayerNameToDesc[poLayer->m_osTargetName] = + std::move(osDescription); m_apoLayers.push_back(std::unique_ptr(poLayer)); return m_apoLayers.back().get(); diff --git a/ogr/ogrsf_frmts/ngw/ngw_api.cpp b/ogr/ogrsf_frmts/ngw/ngw_api.cpp index 12b98ac748c1..03e2536767cf 100644 --- a/ogr/ogrsf_frmts/ngw/ngw_api.cpp +++ b/ogr/ogrsf_frmts/ngw/ngw_api.cpp @@ -215,7 +215,7 @@ Uri ParseUri(const std::string &osUrl) } else { - stOut.osResourceId = osResourceId; + stOut.osResourceId = std::move(osResourceId); } return stOut; diff --git a/ogr/ogrsf_frmts/ngw/ogrngwdriver.cpp b/ogr/ogrsf_frmts/ngw/ogrngwdriver.cpp index 455a5d296c36..2944aa10848e 100644 --- a/ogr/ogrsf_frmts/ngw/ogrngwdriver.cpp +++ b/ogr/ogrsf_frmts/ngw/ogrngwdriver.cpp @@ -302,7 +302,7 @@ static GDALDataset *OGRNGWDriverCreateCopy(const char *pszFilename, if (poTmpDS != nullptr) { bCloseDS = true; - osFilename = osTempFilename; + osFilename = std::move(osTempFilename); poSrcDS = poTmpDS; } else diff --git a/ogr/ogrsf_frmts/ngw/ogrngwlayer.cpp b/ogr/ogrsf_frmts/ngw/ogrngwlayer.cpp index 6ca902d49731..8ec8cd17d3cf 100644 --- a/ogr/ogrsf_frmts/ngw/ogrngwlayer.cpp +++ b/ogr/ogrsf_frmts/ngw/ogrngwlayer.cpp @@ -1421,7 +1421,7 @@ OGRErr OGRNGWLayer::SyncToDisk() // Error message should set in CreateResource. return OGRERR_FAILURE; } - osResourceId = osResourceIdInt; + osResourceId = std::move(osResourceIdInt); OGRLayer::SetMetadataItem("id", osResourceId.c_str()); FetchPermissions(); bNeedSyncStructure = false; @@ -1791,10 +1791,9 @@ OGRErr OGRNGWLayer::SetAttributeFilter(const char *pszQuery) { swq_expr_node *poNode = reinterpret_cast(m_poAttrQuery->GetSWQExpr()); - std::string osWhereIn = TranslateSQLToFilter(poNode); - if (osWhereIn.empty()) + osWhere = TranslateSQLToFilter(poNode); + if (osWhere.empty()) { - osWhere.clear(); bClientSideAttributeFilter = true; CPLDebug( "NGW", @@ -1804,8 +1803,7 @@ OGRErr OGRNGWLayer::SetAttributeFilter(const char *pszQuery) else { bClientSideAttributeFilter = false; - CPLDebug("NGW", "Attribute filter: %s", osWhereIn.c_str()); - osWhere = osWhereIn; + CPLDebug("NGW", "Attribute filter: %s", osWhere.c_str()); } } } diff --git a/ogr/ogrsf_frmts/ogdi/ogrogdidatasource.cpp b/ogr/ogrsf_frmts/ogdi/ogrogdidatasource.cpp index 665b7fe1d701..8d8dc411995d 100644 --- a/ogr/ogrsf_frmts/ogdi/ogrogdidatasource.cpp +++ b/ogr/ogrsf_frmts/ogdi/ogrogdidatasource.cpp @@ -96,6 +96,7 @@ int OGROGDIDataSource::Open(const char *pszNewName) char *pszWorkingName = CPLStrdup(pszNewName); char *pszFamily = strrchr(pszWorkingName, ':'); + CPLAssert(pszFamily); // Don't treat drive name colon as family separator. It is assumed // that drive names are on character long, and preceded by a diff --git a/ogr/ogrsf_frmts/openfilegdb/ogropenfilegdbdatasource_write.cpp b/ogr/ogrsf_frmts/openfilegdb/ogropenfilegdbdatasource_write.cpp index a2a8b19ca96f..2cb4bf294fe2 100644 --- a/ogr/ogrsf_frmts/openfilegdb/ogropenfilegdbdatasource_write.cpp +++ b/ogr/ogrsf_frmts/openfilegdb/ogropenfilegdbdatasource_write.cpp @@ -1561,7 +1561,7 @@ CPLErr OGROpenFileGDBDataSource::FlushCache(bool /*bAtClosing*/) bool OGROpenFileGDBDataSource::AddFieldDomain( std::unique_ptr &&domain, std::string &failureReason) { - const auto domainName = domain->GetName(); + const std::string domainName(domain->GetName()); if (eAccess != GA_Update) { CPLError(CE_Failure, CPLE_NotSupported, @@ -1741,7 +1741,7 @@ bool OGROpenFileGDBDataSource::DeleteFieldDomain( bool OGROpenFileGDBDataSource::UpdateFieldDomain( std::unique_ptr &&domain, std::string &failureReason) { - const auto domainName = domain->GetName(); + const std::string domainName(domain->GetName()); if (eAccess != GA_Update) { CPLError(CE_Failure, CPLE_NotSupported, diff --git a/ogr/ogrsf_frmts/osm/ogrosmlayer.cpp b/ogr/ogrsf_frmts/osm/ogrosmlayer.cpp index de6754d424d7..f54bdddca306 100644 --- a/ogr/ogrsf_frmts/osm/ogrosmlayer.cpp +++ b/ogr/ogrsf_frmts/osm/ogrosmlayer.cpp @@ -1083,7 +1083,7 @@ void OGROSMLayer::AddComputedAttribute(const char *pszName, OGRFieldType eType, oComputedAttribute.nIndex = m_poFeatureDefn->GetFieldCount() - 1; oComputedAttribute.osSQL = pszSQL; oComputedAttribute.hStmt = hStmt; - oComputedAttribute.aosAttrToBind = aosAttrToBind; - oComputedAttribute.anIndexToBind = anIndexToBind; + oComputedAttribute.aosAttrToBind = std::move(aosAttrToBind); + oComputedAttribute.anIndexToBind = std::move(anIndexToBind); oComputedAttribute.bHardcodedZOrder = bHardcodedZOrder; } diff --git a/ogr/ogrsf_frmts/parquet/ogrparquetdriver.cpp b/ogr/ogrsf_frmts/parquet/ogrparquetdriver.cpp index b3a6ada2cc6d..7cf13547e261 100644 --- a/ogr/ogrsf_frmts/parquet/ogrparquetdriver.cpp +++ b/ogr/ogrsf_frmts/parquet/ogrparquetdriver.cpp @@ -322,10 +322,10 @@ static GDALDataset *OpenParquetDatasetWithMetadata( std::shared_ptr factory; PARQUET_ASSIGN_OR_THROW( - factory, - arrow::dataset::ParquetDatasetFactory::Make( - osBasePath + '/' + pszMetadataFile, std::move(fs), - std::make_shared(), options)); + factory, arrow::dataset::ParquetDatasetFactory::Make( + osBasePath + '/' + pszMetadataFile, std::move(fs), + std::make_shared(), + std::move(options))); return OpenFromDatasetFactory(osBasePath, factory, papszOpenOptions); } @@ -353,10 +353,10 @@ OpenParquetDatasetWithoutMetadata(const std::string &osBasePathIn, std::shared_ptr factory; PARQUET_ASSIGN_OR_THROW( - factory, - arrow::dataset::FileSystemDatasetFactory::Make( - std::move(fs), selector, - std::make_shared(), options)); + factory, arrow::dataset::FileSystemDatasetFactory::Make( + std::move(fs), selector, + std::make_shared(), + std::move(options))); return OpenFromDatasetFactory(osBasePath, factory, papszOpenOptions); } diff --git a/ogr/ogrsf_frmts/pgeo/ogrpgeodatasource.cpp b/ogr/ogrsf_frmts/pgeo/ogrpgeodatasource.cpp index 415fb47afa0c..b430620bc027 100644 --- a/ogr/ogrsf_frmts/pgeo/ogrpgeodatasource.cpp +++ b/ogr/ogrsf_frmts/pgeo/ogrpgeodatasource.cpp @@ -307,7 +307,8 @@ int OGRPGeoDataSource::Open(GDALOpenInfo *poOpenInfo) if (auto poRelationship = ParseXMLRelationshipDef(osDefinition)) { - const auto relationshipName = poRelationship->GetName(); + const std::string relationshipName( + poRelationship->GetName()); m_osMapRelationships[relationshipName] = std::move(poRelationship); } diff --git a/ogr/ogrsf_frmts/plscenes/ogrplscenesdatav1dataset.cpp b/ogr/ogrsf_frmts/plscenes/ogrplscenesdatav1dataset.cpp index ecf49cd41206..431177e7970c 100644 --- a/ogr/ogrsf_frmts/plscenes/ogrplscenesdatav1dataset.cpp +++ b/ogr/ogrsf_frmts/plscenes/ogrplscenesdatav1dataset.cpp @@ -594,7 +594,7 @@ GDALDataset *OGRPLScenesDataV1Dataset::OpenRasterScene(GDALOpenInfo *poOpenInfo, VSIStatBufL sStat; if (VSIStatL(osTmpURL, &sStat) == 0 && sStat.st_size > 0) { - osRasterURL = osTmpURL; + osRasterURL = std::move(osTmpURL); } else { diff --git a/ogr/ogrsf_frmts/sqlite/ogrsqlitedatasource.cpp b/ogr/ogrsf_frmts/sqlite/ogrsqlitedatasource.cpp index 751b511ce2ab..6942e248ba07 100644 --- a/ogr/ogrsf_frmts/sqlite/ogrsqlitedatasource.cpp +++ b/ogr/ogrsf_frmts/sqlite/ogrsqlitedatasource.cpp @@ -4583,7 +4583,7 @@ int OGRSQLiteDataSource::FetchSRSId(const OGRSpatialReference *poSRS) if (nSRSId != m_nUndefinedSRID) { - auto poCachedSRS = new OGRSpatialReference(oSRS); + auto poCachedSRS = new OGRSpatialReference(std::move(oSRS)); poCachedSRS->SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER); AddSRIDToCache(nSRSId, poCachedSRS); } diff --git a/ogr/ogrsf_frmts/sqlite/ogrsqliteexecutesql.cpp b/ogr/ogrsf_frmts/sqlite/ogrsqliteexecutesql.cpp index 940ec56f2351..c697ebd02ef2 100644 --- a/ogr/ogrsf_frmts/sqlite/ogrsqliteexecutesql.cpp +++ b/ogr/ogrsf_frmts/sqlite/ogrsqliteexecutesql.cpp @@ -141,7 +141,7 @@ static CPLString OGR2SQLITEExtractUnquotedString(const char **ppszSQLCommand) static LayerDesc OGR2SQLITEExtractLayerDesc(const char **ppszSQLCommand) { - CPLString osStr; + std::string osStr; const char *pszSQLCommand = *ppszSQLCommand; LayerDesc oLayerDesc; @@ -162,7 +162,7 @@ static LayerDesc OGR2SQLITEExtractLayerDesc(const char **ppszSQLCommand) } else { - oLayerDesc.osLayerName = osStr; + oLayerDesc.osLayerName = std::move(osStr); } oLayerDesc.osOriginalStr.resize(pszSQLCommand - pszOriginalStrStart); diff --git a/ogr/ogrsf_frmts/wfs/ogr_wfs.h b/ogr/ogrsf_frmts/wfs/ogr_wfs.h index 4b62891078e8..c3eb42bff124 100644 --- a/ogr/ogrsf_frmts/wfs/ogr_wfs.h +++ b/ogr/ogrsf_frmts/wfs/ogr_wfs.h @@ -205,7 +205,7 @@ class OGRWFSLayer final : public OGRLayer OGRFeatureDefn *ParseSchema(const CPLXMLNode *psSchema); OGRFeatureDefn *BuildLayerDefn(OGRFeatureDefn *poSrcFDefn = nullptr); - OGRErr DeleteFromFilter(CPLString osOGCFilter); + OGRErr DeleteFromFilter(const std::string &osOGCFilter); const std::vector &GetLastInsertedFIDList() { diff --git a/ogr/ogrsf_frmts/wfs/ogroapifdriver.cpp b/ogr/ogrsf_frmts/wfs/ogroapifdriver.cpp index 585c99632ba1..4eb066a26d46 100644 --- a/ogr/ogrsf_frmts/wfs/ogroapifdriver.cpp +++ b/ogr/ogrsf_frmts/wfs/ogroapifdriver.cpp @@ -302,11 +302,11 @@ CPLString OGROAPIFDataset::ReinjectAuthInURL(const CPLString &osURL) const { auto osUserPwd = m_osRootURL.substr( strlen("https://"), nArobaseInURLPos - strlen("https://")); - auto osServer = + std::string osServer( nFirstSlashPos == std::string::npos ? m_osRootURL.substr(nArobaseInURLPos + 1) : m_osRootURL.substr(nArobaseInURLPos + 1, - nFirstSlashPos - nArobaseInURLPos); + nFirstSlashPos - nArobaseInURLPos)); if (STARTS_WITH(osRet, ("https://" + osServer).c_str())) { osRet = "https://" + osUserPwd + "@" + @@ -2085,7 +2085,7 @@ OGRFeature *OGROAPIFLayer::GetNextRawFeature() if (oLinks.IsValid()) { int nCountRelNext = 0; - CPLString osNextURL; + std::string osNextURL; for (int i = 0; i < oLinks.Size(); i++) { CPLJSONObject oLink = oLinks[i]; @@ -2113,7 +2113,7 @@ OGRFeature *OGROAPIFLayer::GetNextRawFeature() if (nCountRelNext == 1 && m_osGetURL.empty()) { // In case we go a "rel": "next" without a "type" - m_osGetURL = osNextURL; + m_osGetURL = std::move(osNextURL); } } diff --git a/ogr/ogrsf_frmts/wfs/ogrwfslayer.cpp b/ogr/ogrsf_frmts/wfs/ogrwfslayer.cpp index 443e402c1ad8..f91c37e73b08 100644 --- a/ogr/ogrsf_frmts/wfs/ogrwfslayer.cpp +++ b/ogr/ogrsf_frmts/wfs/ogrwfslayer.cpp @@ -2443,7 +2443,7 @@ OGRFeature *OGRWFSLayer::GetFeature(GIntBig nFID) /* DeleteFromFilter() */ /************************************************************************/ -OGRErr OGRWFSLayer::DeleteFromFilter(CPLString osOGCFilter) +OGRErr OGRWFSLayer::DeleteFromFilter(const std::string &osOGCFilter) { if (!TestCapability(OLCDeleteFeature)) { diff --git a/port/cpl_aws.cpp b/port/cpl_aws.cpp index f18acf0ff832..d7676b33c160 100644 --- a/port/cpl_aws.cpp +++ b/port/cpl_aws.cpp @@ -1142,9 +1142,8 @@ bool VSIS3HandleHelper::GetConfigurationFromAWSConfigFiles( constexpr char SEP_STRING[] = "/"; #endif - std::string osDotAws(pszHome ? pszHome : ""); - osDotAws += SEP_STRING; - osDotAws += ".aws"; + const std::string osDotAws( + std::string(pszHome ? pszHome : "").append(SEP_STRING).append(".aws")); // Read first ~/.aws/credential file @@ -1562,8 +1561,9 @@ bool VSIS3HandleHelper::GetConfiguration( osSecretAccessKey, osAccessKeyId, osSessionToken)) { CPLMutexHolder oHolder(&ghMutex); - gosRoleArnWebIdentity = osRoleArnSP; - gosWebIdentityTokenFile = osWebIdentityTokenFile; + gosRoleArnWebIdentity = std::move(osRoleArnSP); + gosWebIdentityTokenFile = + std::move(osWebIdentityTokenFile); } } } @@ -1614,9 +1614,9 @@ bool VSIS3HandleHelper::GetConfiguration( gosGlobalSessionToken = osTempSessionToken; gosRegion = osRegion; } - osSecretAccessKey = osTempSecretAccessKey; - osAccessKeyId = osTempAccessKeyId; - osSessionToken = osTempSessionToken; + osSecretAccessKey = std::move(osTempSecretAccessKey); + osAccessKeyId = std::move(osTempAccessKeyId); + osSessionToken = std::move(osTempSessionToken); eCredentialsSource = AWSCredentialsSource::ASSUMED_ROLE; return true; } @@ -1831,9 +1831,9 @@ void VSIS3HandleHelper::RefreshCredentials(const std::string &osPathForOption, osSecretAccessKey, osAccessKeyId, osSessionToken)) { - m_osSecretAccessKey = osSecretAccessKey; - m_osAccessKeyId = osAccessKeyId; - m_osSessionToken = osSessionToken; + m_osSecretAccessKey = std::move(osSecretAccessKey); + m_osAccessKeyId = std::move(osAccessKeyId); + m_osSessionToken = std::move(osSessionToken); } } else if (m_eCredentialsSource == AWSCredentialsSource::ASSUMED_ROLE) @@ -1844,9 +1844,9 @@ void VSIS3HandleHelper::RefreshCredentials(const std::string &osPathForOption, bForceRefresh, osSecretAccessKey, osAccessKeyId, osSessionToken, osRegion)) { - m_osSecretAccessKey = osSecretAccessKey; - m_osAccessKeyId = osAccessKeyId; - m_osSessionToken = osSessionToken; + m_osSecretAccessKey = std::move(osSecretAccessKey); + m_osAccessKeyId = std::move(osAccessKeyId); + m_osSessionToken = std::move(osSessionToken); } } else if (m_eCredentialsSource == AWSCredentialsSource::WEB_IDENTITY) @@ -1857,9 +1857,9 @@ void VSIS3HandleHelper::RefreshCredentials(const std::string &osPathForOption, std::string(), osSecretAccessKey, osAccessKeyId, osSessionToken)) { - m_osSecretAccessKey = osSecretAccessKey; - m_osAccessKeyId = osAccessKeyId; - m_osSessionToken = osSessionToken; + m_osSecretAccessKey = std::move(osSecretAccessKey); + m_osAccessKeyId = std::move(osAccessKeyId); + m_osSessionToken = std::move(osSessionToken); } } } diff --git a/port/cpl_azure.cpp b/port/cpl_azure.cpp index bc791d51d70e..b1fb4b73d236 100644 --- a/port/cpl_azure.cpp +++ b/port/cpl_azure.cpp @@ -317,7 +317,7 @@ GetConfigurationFromIMDSCredentials(const std::string &osPathForOption, CPLAzureCachedToken cachedToken; cachedToken.osAccessToken = osAccessToken; cachedToken.nExpiresOn = nExpiresOn; - goMapIMDSURLToCachedToken[osURLResource] = cachedToken; + goMapIMDSURLToCachedToken[osURLResource] = std::move(cachedToken); CPLDebug("AZURE", "Storing credentials for %s until " CPL_FRMT_GIB, osURLResource.c_str(), nExpiresOn); } diff --git a/port/cpl_google_cloud.cpp b/port/cpl_google_cloud.cpp index 4e6c3c8090eb..8a9cb42e22ba 100644 --- a/port/cpl_google_cloud.cpp +++ b/port/cpl_google_cloud.cpp @@ -629,8 +629,8 @@ bool VSIGSHandleHelper::GetConfiguration(const std::string &osPathForOption, } else if (nCount == 2) { - osClientId = osOAuth2ClientId; - osClientSecret = osOAuth2ClientSecret; + osClientId = std::move(osOAuth2ClientId); + osClientSecret = std::move(osOAuth2ClientSecret); bClientInfoFromFile = true; } } diff --git a/port/cpl_odbc.cpp b/port/cpl_odbc.cpp index a9de2e0bce65..b9af40aba3d0 100644 --- a/port/cpl_odbc.cpp +++ b/port/cpl_odbc.cpp @@ -193,7 +193,7 @@ bool CPLODBCDriverInstaller::FindMdbToolsDriverLib(CPLString &osDriverFile) if (LibraryExists(strLibPath.c_str())) { // Save custom driver path - osDriverFile = strLibPath; + osDriverFile = std::move(strLibPath); return true; } } diff --git a/port/cpl_swift.cpp b/port/cpl_swift.cpp index c150ed709f74..3c889c691e05 100644 --- a/port/cpl_swift.cpp +++ b/port/cpl_swift.cpp @@ -194,9 +194,9 @@ bool VSISwiftHandleHelper::AuthV1(const std::string &osPathForOption, // Cache credentials { CPLMutexHolder oHolder(&g_hMutex); - g_osLastAuthURL = osAuthURL; - g_osLastUser = osUser; - g_osLastKey = osKey; + g_osLastAuthURL = std::move(osAuthURL); + g_osLastUser = std::move(osUser); + g_osLastKey = std::move(osKey); g_osLastStorageURL = osStorageURL; g_osLastAuthToken = osAuthToken; } @@ -439,9 +439,9 @@ bool VSISwiftHandleHelper::AuthV3(const std::string &osPathForOption, // Cache credentials { CPLMutexHolder oHolder(&g_hMutex); - g_osLastAuthURL = osAuthURL; - g_osLastUser = osAuthID; - g_osLastKey = osAuthKey; + g_osLastAuthURL = std::move(osAuthURL); + g_osLastUser = std::move(osAuthID); + g_osLastKey = std::move(osAuthKey); g_osLastStorageURL = osStorageURL; g_osLastAuthToken = osAuthToken; } diff --git a/port/cpl_vsil_adls.cpp b/port/cpl_vsil_adls.cpp index a1ef3d73dba7..b2f399b6b74f 100644 --- a/port/cpl_vsil_adls.cpp +++ b/port/cpl_vsil_adls.cpp @@ -429,7 +429,7 @@ bool VSIDIRADLS::AnalysePathList(const std::string &osBaseURL, prop.bIsDirectory = CPL_TO_BOOL(VSI_ISDIR(entry->nMode)); prop.nMode = entry->nMode; prop.mTime = static_cast(entry->nMTime); - prop.ETag = ETag; + prop.ETag = std::move(ETag); std::string osCachedFilename = osBaseURL + "/" + CPLAWSURLEncode(osName, false); @@ -508,7 +508,7 @@ bool VSIDIRADLS::AnalyseFilesystemList(const std::string &osBaseURL, prop.fileSize = 0; prop.bIsDirectory = true; prop.mTime = static_cast(entry->nMTime); - prop.ETag = ETag; + prop.ETag = std::move(ETag); std::string osCachedFilename = osBaseURL + CPLAWSURLEncode(osName, false); diff --git a/port/cpl_vsil_az.cpp b/port/cpl_vsil_az.cpp index e94983618ce5..fa25c27ab833 100644 --- a/port/cpl_vsil_az.cpp +++ b/port/cpl_vsil_az.cpp @@ -301,7 +301,7 @@ bool VSIDIRAz::AnalyseAzureFileList(const std::string &osBaseURL, prop.fileSize = entry->nSize; prop.bIsDirectory = false; prop.mTime = static_cast(entry->nMTime); - prop.ETag = ETag; + prop.ETag = std::move(ETag); prop.nMode = entry->nMode; std::string osCachedFilename = diff --git a/port/cpl_vsil_curl.cpp b/port/cpl_vsil_curl.cpp index da802d5be6d9..c5a87cb85d45 100644 --- a/port/cpl_vsil_curl.cpp +++ b/port/cpl_vsil_curl.cpp @@ -4709,7 +4709,7 @@ char **VSICurlFilesystemHandlerBase::GetFileList(const char *pszDirname, bool bListDir = true; bool bEmptyDir = false; - std::string osURL(VSICurlGetURLFromFilename( + const std::string osURL(VSICurlGetURLFromFilename( pszDirname, nullptr, nullptr, nullptr, nullptr, &bListDir, &bEmptyDir, nullptr, nullptr, nullptr)); if (bEmptyDir) diff --git a/port/cpl_vsil_s3.cpp b/port/cpl_vsil_s3.cpp index 3956ebfc46d4..5bbb4504d1a7 100644 --- a/port/cpl_vsil_s3.cpp +++ b/port/cpl_vsil_s3.cpp @@ -358,7 +358,7 @@ bool VSIDIRS3::AnalyseS3FileList( prop.fileSize = entry->nSize; prop.bIsDirectory = (entry->nMode == S_IFDIR); prop.mTime = static_cast(entry->nMTime); - prop.ETag = ETag; + prop.ETag = std::move(ETag); std::string osCachedFilename = osBaseURL + CPLAWSURLEncode(osPrefix, false) + @@ -4223,7 +4223,8 @@ bool IVSIS3LikeFSHandler::Sync(const char *pszSource, const char *pszTarget, if (CanSkipDownloadFromNetworkToLocal( osSubSource.c_str(), osSubTarget.c_str(), chunk.nMTime, oIterExistingTarget->second.nMTime, - [&chunk](const char *) { return chunk.osETag; })) + [&chunk](const char *) -> std::string + { return chunk.osETag; })) { bSkip = true; } @@ -4299,7 +4300,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[osSubTarget] = def; + oMapMultiPartDefs[osSubTarget] = std::move(def); } else { @@ -4400,7 +4401,7 @@ bool IVSIS3LikeFSHandler::Sync(const char *pszSource, const char *pszTarget, if (CanSkipDownloadFromNetworkToLocal( 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( diff --git a/port/cpl_xml_validate.cpp b/port/cpl_xml_validate.cpp index 29070d957b65..fbdca7b3658b 100644 --- a/port/cpl_xml_validate.cpp +++ b/port/cpl_xml_validate.cpp @@ -766,10 +766,10 @@ static xmlParserInputPtr CPLExternalEntityLoader(const char *URL, } else if (strcmp(URL, "http://www.w3.org/2001/xml.xsd") == 0) { - CPLString osTmp = CPLFindLocalXSD("xml.xsd"); + std::string osTmp = CPLFindLocalXSD("xml.xsd"); if (!osTmp.empty()) { - osURL = osTmp; + osURL = std::move(osTmp); URL = osURL.c_str(); } else @@ -782,10 +782,10 @@ static xmlParserInputPtr CPLExternalEntityLoader(const char *URL, } else if (strcmp(URL, "http://www.w3.org/1999/xlink.xsd") == 0) { - CPLString osTmp = CPLFindLocalXSD("xlink.xsd"); + std::string osTmp = CPLFindLocalXSD("xlink.xsd"); if (!osTmp.empty()) { - osURL = osTmp; + osURL = std::move(osTmp); URL = osURL.c_str(); } else