From 9a9d54908af1fb978c6e6705c3f6845130743c7b Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Mon, 13 Jan 2025 20:00:01 +0100 Subject: [PATCH] frmts/ ogr/ .cpp: replace all remaining uses of CPLGetDirname() with CPLGetDirnameSafe() --- frmts/aigrid/aigdataset.cpp | 2 +- frmts/esric/esric_dataset.cpp | 3 +- frmts/gtiff/gtiffdataset_read.cpp | 6 +-- frmts/jaxapalsar/jaxapalsardataset.cpp | 19 ++++++---- frmts/netcdf/netcdfdataset.cpp | 5 ++- frmts/nitf/ecrgtocdataset.cpp | 37 ++++++++++--------- frmts/sentinel2/sentinel2dataset.cpp | 10 ++--- frmts/vrt/vrtdataset.cpp | 23 +++++++----- frmts/wms/gdalwmscache.cpp | 3 +- frmts/zarr/zarr_sharedresource.cpp | 6 +-- frmts/zarr/zarr_v2_array.cpp | 16 ++++---- ogr/ogrsf_frmts/gmlas/ogrgmlasxsdcache.cpp | 6 +-- .../libkml/ogrlibkmlfeaturestyle.cpp | 5 ++- .../miramon/ogrmiramondatasource.cpp | 2 +- ogr/ogrsf_frmts/miramon/ogrmiramonlayer.cpp | 35 +++++++++++++----- 15 files changed, 102 insertions(+), 76 deletions(-) diff --git a/frmts/aigrid/aigdataset.cpp b/frmts/aigrid/aigdataset.cpp index b78a5c27e4e8..f96710b15b84 100644 --- a/frmts/aigrid/aigdataset.cpp +++ b/frmts/aigrid/aigdataset.cpp @@ -533,7 +533,7 @@ GDALDataset *AIGDataset::Open(GDALOpenInfo *poOpenInfo) if (osCoverName.size() > 4 && EQUAL(osCoverName.c_str() + osCoverName.size() - 4, ".adf")) { - osCoverName = CPLGetDirname(poOpenInfo->pszFilename); + osCoverName = CPLGetDirnameSafe(poOpenInfo->pszFilename); if (osCoverName == "") osCoverName = "."; } diff --git a/frmts/esric/esric_dataset.cpp b/frmts/esric/esric_dataset.cpp index 06eaeb1c3f3f..d6e662e101b0 100644 --- a/frmts/esric/esric_dataset.cpp +++ b/frmts/esric/esric_dataset.cpp @@ -633,8 +633,7 @@ GDALDataset *ECDataset::Open(GDALOpenInfo *poOpenInfo, return nullptr; } auto ds = new ECDataset(); - ds->dname.Printf("%s/_alllayers", - CPLGetDirname(poOpenInfo->pszFilename)); + ds->dname = CPLGetDirnameSafe(poOpenInfo->pszFilename) + "/_alllayers"; CPLErr error = ds->Initialize(CacheInfo); CPLDestroyXMLNode(config); if (CE_None != error) diff --git a/frmts/gtiff/gtiffdataset_read.cpp b/frmts/gtiff/gtiffdataset_read.cpp index 42f4d879020e..46c5cd0ccfb1 100644 --- a/frmts/gtiff/gtiffdataset_read.cpp +++ b/frmts/gtiff/gtiffdataset_read.cpp @@ -5770,12 +5770,12 @@ CSLConstList GTiffDataset::GetSiblingFiles() m_bHasGotSiblingFiles = true; const int nMaxFiles = atoi(CPLGetConfigOption("GDAL_READDIR_LIMIT_ON_OPEN", "1000")); - CPLStringList aosSiblingFiles( - VSIReadDirEx(CPLGetDirnameSafe(m_pszFilename).c_str(), nMaxFiles)); + const std::string osDirname = CPLGetDirnameSafe(m_pszFilename); + CPLStringList aosSiblingFiles(VSIReadDirEx(osDirname.c_str(), nMaxFiles)); if (nMaxFiles > 0 && aosSiblingFiles.size() > nMaxFiles) { CPLDebug("GTiff", "GDAL_READDIR_LIMIT_ON_OPEN reached on %s", - CPLGetDirname(m_pszFilename)); + osDirname.c_str()); aosSiblingFiles.clear(); } oOvManager.TransferSiblingFiles(aosSiblingFiles.StealList()); diff --git a/frmts/jaxapalsar/jaxapalsardataset.cpp b/frmts/jaxapalsar/jaxapalsardataset.cpp index 684bf898bd52..d8ef19f4b95e 100644 --- a/frmts/jaxapalsar/jaxapalsardataset.cpp +++ b/frmts/jaxapalsar/jaxapalsardataset.cpp @@ -579,15 +579,16 @@ GDALDataset *PALSARJaxaDataset::Open(GDALOpenInfo *poOpenInfo) /* Try to read each of the polarizations */ const size_t nImgFileLen = - strlen(CPLGetDirnameSafe(poOpenInfo->pszFilename).c_str()) + - strlen(pszSuffix) + 8; + CPLGetDirnameSafe(poOpenInfo->pszFilename).size() + strlen(pszSuffix) + + 8; char *pszImgFile = (char *)CPLMalloc(nImgFileLen); int nBandNum = 1; /* HH */ snprintf(pszImgFile, nImgFileLen, "%s%sIMG-HH%s", - CPLGetDirname(poOpenInfo->pszFilename), SEP_STRING, pszSuffix); + CPLGetDirnameSafe(poOpenInfo->pszFilename).c_str(), SEP_STRING, + pszSuffix); VSILFILE *fpHH = VSIFOpenL(pszImgFile, "rb"); if (fpHH != nullptr) { @@ -597,7 +598,8 @@ GDALDataset *PALSARJaxaDataset::Open(GDALOpenInfo *poOpenInfo) /* HV */ snprintf(pszImgFile, nImgFileLen, "%s%sIMG-HV%s", - CPLGetDirname(poOpenInfo->pszFilename), SEP_STRING, pszSuffix); + CPLGetDirnameSafe(poOpenInfo->pszFilename).c_str(), SEP_STRING, + pszSuffix); VSILFILE *fpHV = VSIFOpenL(pszImgFile, "rb"); if (fpHV != nullptr) { @@ -607,7 +609,8 @@ GDALDataset *PALSARJaxaDataset::Open(GDALOpenInfo *poOpenInfo) /* VH */ snprintf(pszImgFile, nImgFileLen, "%s%sIMG-VH%s", - CPLGetDirname(poOpenInfo->pszFilename), SEP_STRING, pszSuffix); + CPLGetDirnameSafe(poOpenInfo->pszFilename).c_str(), SEP_STRING, + pszSuffix); VSILFILE *fpVH = VSIFOpenL(pszImgFile, "rb"); if (fpVH != nullptr) { @@ -617,7 +620,8 @@ GDALDataset *PALSARJaxaDataset::Open(GDALOpenInfo *poOpenInfo) /* VV */ snprintf(pszImgFile, nImgFileLen, "%s%sIMG-VV%s", - CPLGetDirname(poOpenInfo->pszFilename), SEP_STRING, pszSuffix); + CPLGetDirnameSafe(poOpenInfo->pszFilename).c_str(), SEP_STRING, + pszSuffix); VSILFILE *fpVV = VSIFOpenL(pszImgFile, "rb"); if (fpVV != nullptr) { @@ -656,7 +660,8 @@ GDALDataset *PALSARJaxaDataset::Open(GDALOpenInfo *poOpenInfo) strlen(pszSuffix) + 5; char *pszLeaderFilename = (char *)CPLMalloc(nLeaderFilenameLen); snprintf(pszLeaderFilename, nLeaderFilenameLen, "%s%sLED%s", - CPLGetDirname(poOpenInfo->pszFilename), SEP_STRING, pszSuffix); + CPLGetDirnameSafe(poOpenInfo->pszFilename).c_str(), SEP_STRING, + pszSuffix); VSILFILE *fpLeader = VSIFOpenL(pszLeaderFilename, "rb"); /* check if the leader is actually present */ diff --git a/frmts/netcdf/netcdfdataset.cpp b/frmts/netcdf/netcdfdataset.cpp index 7c6f33154612..2680d4892899 100644 --- a/frmts/netcdf/netcdfdataset.cpp +++ b/frmts/netcdf/netcdfdataset.cpp @@ -9223,8 +9223,9 @@ netCDFDataset *netCDFDataset::CreateLL(const char *pszFilename, int nXSize, // Works around bug of msys2 netCDF 4.9.0 package where nc_create() // crashes VSIStatBuf sStat; - const char *pszDir = CPLGetDirname(osFilenameForNCCreate.c_str()); - if (VSIStat(pszDir, &sStat) != 0) + const std::string osDirname = + CPLGetDirnameSafe(osFilenameForNCCreate.c_str()); + if (VSIStat(osDirname.c_str(), &sStat) != 0) { CPLError(CE_Failure, CPLE_OpenFailed, "Unable to create netCDF file %s: non existing output " diff --git a/frmts/nitf/ecrgtocdataset.cpp b/frmts/nitf/ecrgtocdataset.cpp index d4d1e19c126a..8e6b04a1f98d 100644 --- a/frmts/nitf/ecrgtocdataset.cpp +++ b/frmts/nitf/ecrgtocdataset.cpp @@ -471,7 +471,7 @@ bool ECRGTOCSource::ValidateOpenedBand(GDALRasterBand *poBand) const /* BuildFullName() */ /************************************************************************/ -static const char *BuildFullName(const char *pszTOCFilename, +static std::string BuildFullName(const char *pszTOCFilename, const char *pszFramePath, const char *pszFrameName) { @@ -486,24 +486,25 @@ static const char *BuildFullName(const char *pszTOCFilename, if (pszPath[i] == '\\') pszPath[i] = '/'; } - const char *pszName = CPLFormFilename(pszPath, pszFrameName, nullptr); + const std::string osName = + CPLFormFilenameSafe(pszPath, pszFrameName, nullptr); CPLFree(pszPath); pszPath = nullptr; - const char *pszTOCPath = CPLGetDirname(pszTOCFilename); - const char *pszFirstSlashInName = strchr(pszName, '/'); - if (pszFirstSlashInName != nullptr) + std::string osTOCPath = CPLGetDirnameSafe(pszTOCFilename); + const auto nPosFirstSlashInName = osName.find('/'); + if (nPosFirstSlashInName != std::string::npos) { - int nFirstDirLen = static_cast(pszFirstSlashInName - pszName); - if (static_cast(strlen(pszTOCPath)) >= nFirstDirLen + 1 && - (pszTOCPath[strlen(pszTOCPath) - (nFirstDirLen + 1)] == '/' || - pszTOCPath[strlen(pszTOCPath) - (nFirstDirLen + 1)] == '\\') && - strncmp(pszTOCPath + strlen(pszTOCPath) - nFirstDirLen, pszName, - nFirstDirLen) == 0) + if (osTOCPath.size() >= nPosFirstSlashInName + 1 && + (osTOCPath[osTOCPath.size() - (nPosFirstSlashInName + 1)] == '/' || + osTOCPath[osTOCPath.size() - (nPosFirstSlashInName + 1)] == + '\\') && + strncmp(osTOCPath.c_str() + osTOCPath.size() - nPosFirstSlashInName, + osName.c_str(), nPosFirstSlashInName) == 0) { - pszTOCPath = CPLGetDirname(pszTOCPath); + osTOCPath = CPLGetDirnameSafe(osTOCPath.c_str()); } } - return CPLProjectRelativeFilename(pszTOCPath, pszName); + return CPLProjectRelativeFilenameSafe(osTOCPath.c_str(), osName.c_str()); } /************************************************************************/ @@ -571,7 +572,7 @@ GDALDataset *ECRGTOCSubDataset::Build( for (int i = 0; i < static_cast(aosFrameDesc.size()); i++) { - const char *pszName = BuildFullName( + const std::string osName = BuildFullName( pszTOCFilename, aosFrameDesc[i].pszPath, aosFrameDesc[i].pszName); double dfMinX = 0.0; @@ -590,7 +591,7 @@ GDALDataset *ECRGTOCSubDataset::Build( static_cast((dfMaxY - dfMinY) / dfPixelYSize + 0.5); poVirtualDS->papszFileList = - CSLAddString(poVirtualDS->papszFileList, pszName); + CSLAddString(poVirtualDS->papszFileList, osName.c_str()); for (int j = 0; j < 3; j++) { @@ -599,7 +600,7 @@ GDALDataset *ECRGTOCSubDataset::Build( poVirtualDS->GetRasterBand(j + 1)); /* Place the raster band at the right position in the VRT */ auto poSource = new ECRGTOCSource( - pszName, j + 1, nFrameXSize, nFrameYSize, + osName.c_str(), j + 1, nFrameXSize, nFrameYSize, static_cast((dfMinX - dfGlobalMinX) / dfGlobalPixelXSize + 0.5), static_cast((dfGlobalMaxY - dfMaxY) / dfGlobalPixelYSize + @@ -849,10 +850,10 @@ GDALDataset *ECRGTOCDataset::Build(const char *pszTOCFilename, nValidFrames++; - const char *pszFullName = BuildFullName( + const std::string osFullName = BuildFullName( pszTOCFilename, pszFramePath, pszFrameName); poDS->papszFileList = - CSLAddString(poDS->papszFileList, pszFullName); + CSLAddString(poDS->papszFileList, osFullName.c_str()); if (!bGlobalExtentValid) { diff --git a/frmts/sentinel2/sentinel2dataset.cpp b/frmts/sentinel2/sentinel2dataset.cpp index 541260a140d9..32d1caa5602e 100644 --- a/frmts/sentinel2/sentinel2dataset.cpp +++ b/frmts/sentinel2/sentinel2dataset.cpp @@ -945,7 +945,7 @@ static bool SENTINEL2GetGranuleList( const int nOffset = std::min(nBytes, static_cast(sizeof(szPointerFilename) - 1)); szPointerFilename[nOffset] = '\0'; - osDirname = CPLGetDirname(szPointerFilename); + osDirname = CPLGetDirnameSafe(szPointerFilename); } #endif @@ -2337,7 +2337,7 @@ static bool SENTINEL2GetGranuleList_L1CSafeCompact( const int nOffset = std::min(nBytes, static_cast(sizeof(szPointerFilename) - 1)); szPointerFilename[nOffset] = '\0'; - osDirname = CPLGetDirname(szPointerFilename); + osDirname = CPLGetDirnameSafe(szPointerFilename); } #endif @@ -2374,7 +2374,7 @@ static bool SENTINEL2GetGranuleList_L1CSafeCompact( // --> GRANULE/L1C_T30TXT_A007999_20170102T111441/MTD_TL.xml oDesc.osMTDTLPath = osDirname + chSeparator + - CPLGetDirname(CPLGetDirnameSafe(pszImageFile).c_str()) + + CPLGetDirnameSafe(CPLGetDirnameSafe(pszImageFile).c_str()) + chSeparator + "MTD_TL.xml"; osList.push_back(oDesc); } @@ -2429,7 +2429,7 @@ static bool SENTINEL2GetGranuleList_L2ASafeCompact( const int nOffset = std::min(nBytes, static_cast(sizeof(szPointerFilename) - 1)); szPointerFilename[nOffset] = '\0'; - osDirname = CPLGetDirname(szPointerFilename); + osDirname = CPLGetDirnameSafe(szPointerFilename); } #endif @@ -2475,7 +2475,7 @@ static bool SENTINEL2GetGranuleList_L2ASafeCompact( // --> GRANULE/L1C_T30TXT_A007999_20170102T111441/MTD_TL.xml oDesc.osMTDTLPath = osDirname + chSeparator + - CPLGetDirname(CPLGetDirnameSafe(pszImageFile).c_str()); + CPLGetDirnameSafe(CPLGetDirnameSafe(pszImageFile).c_str()); if (oDesc.osMTDTLPath.size() < 9) { CPLDebug("SENTINEL2", "MTDTL path too short"); diff --git a/frmts/vrt/vrtdataset.cpp b/frmts/vrt/vrtdataset.cpp index c5a6f793eda8..c5617875f851 100644 --- a/frmts/vrt/vrtdataset.cpp +++ b/frmts/vrt/vrtdataset.cpp @@ -797,8 +797,8 @@ GDALDataset *VRTDataset::Open(GDALOpenInfo *poOpenInfo) pszXML = reinterpret_cast(pabyOut); char *pszCurDir = CPLGetCurrentDir(); - const char *currentVrtFilename = - CPLProjectRelativeFilename(pszCurDir, poOpenInfo->pszFilename); + std::string currentVrtFilename = + CPLProjectRelativeFilenameSafe(pszCurDir, poOpenInfo->pszFilename); CPLString osInitialCurrentVrtFilename(currentVrtFilename); CPLFree(pszCurDir); @@ -808,7 +808,7 @@ GDALDataset *VRTDataset::Open(GDALOpenInfo *poOpenInfo) while (true) { VSIStatBuf statBuffer; - int lstatCode = lstat(currentVrtFilename, &statBuffer); + int lstatCode = lstat(currentVrtFilename.c_str(), &statBuffer); if (lstatCode == -1) { if (errno == ENOENT) @@ -821,7 +821,7 @@ GDALDataset *VRTDataset::Open(GDALOpenInfo *poOpenInfo) CPL_IGNORE_RET_VAL(VSIFCloseL(fp)); CPLFree(pszXML); CPLError(CE_Failure, CPLE_FileIO, "Failed to lstat %s: %s", - currentVrtFilename, VSIStrerror(errno)); + currentVrtFilename.c_str(), VSIStrerror(errno)); return nullptr; } } @@ -831,8 +831,9 @@ GDALDataset *VRTDataset::Open(GDALOpenInfo *poOpenInfo) break; } - const int bufferSize = static_cast(readlink( - currentVrtFilename, filenameBuffer, sizeof(filenameBuffer))); + const int bufferSize = static_cast( + readlink(currentVrtFilename.c_str(), filenameBuffer, + sizeof(filenameBuffer))); if (bufferSize != -1) { filenameBuffer[std::min( @@ -840,8 +841,9 @@ GDALDataset *VRTDataset::Open(GDALOpenInfo *poOpenInfo) 0; // The filename in filenameBuffer might be a relative path // from the linkfile resolve it before looping - currentVrtFilename = CPLProjectRelativeFilename( - CPLGetDirname(currentVrtFilename), filenameBuffer); + currentVrtFilename = CPLProjectRelativeFilenameSafe( + CPLGetDirnameSafe(currentVrtFilename.c_str()).c_str(), + filenameBuffer); } else { @@ -849,7 +851,7 @@ GDALDataset *VRTDataset::Open(GDALOpenInfo *poOpenInfo) CPLFree(pszXML); CPLError(CE_Failure, CPLE_FileIO, "Failed to read filename from symlink %s: %s", - currentVrtFilename, VSIStrerror(errno)); + currentVrtFilename.c_str(), VSIStrerror(errno)); return nullptr; } } @@ -859,7 +861,8 @@ GDALDataset *VRTDataset::Open(GDALOpenInfo *poOpenInfo) pszVRTPath = CPLStrdup(CPLGetPathSafe(poOpenInfo->pszFilename).c_str()); else - pszVRTPath = CPLStrdup(CPLGetPathSafe(currentVrtFilename).c_str()); + pszVRTPath = + CPLStrdup(CPLGetPathSafe(currentVrtFilename.c_str()).c_str()); CPL_IGNORE_RET_VAL(VSIFCloseL(fp)); } diff --git a/frmts/wms/gdalwmscache.cpp b/frmts/wms/gdalwmscache.cpp index eab071122a1c..771012092616 100644 --- a/frmts/wms/gdalwmscache.cpp +++ b/frmts/wms/gdalwmscache.cpp @@ -182,8 +182,7 @@ class GDALWMSFileCache : public GDALWMSCacheImpl return; } // Recursive makedirs, ignoring errors - const char *pszDirPath = CPLGetDirname(pszPath); - MakeDirs(pszDirPath); + MakeDirs(CPLGetDirnameSafe(pszPath).c_str()); VSIMkdir(pszPath, 0744); } diff --git a/frmts/zarr/zarr_sharedresource.cpp b/frmts/zarr/zarr_sharedresource.cpp index 615a16626171..f9a51ade7fc4 100644 --- a/frmts/zarr/zarr_sharedresource.cpp +++ b/frmts/zarr/zarr_sharedresource.cpp @@ -85,9 +85,9 @@ std::shared_ptr ZarrSharedResource::OpenRootGroup() { // If opening a NCZarr array, initialize its group from NCZarr // metadata. - const std::string osGroupFilename(CPLFormFilename( - CPLGetDirname(m_osRootDirectoryName.c_str()), ".zgroup", - nullptr)); + const std::string osGroupFilename(CPLFormFilenameSafe( + CPLGetDirnameSafe(m_osRootDirectoryName.c_str()).c_str(), + ".zgroup", nullptr)); if (VSIStatL(osGroupFilename.c_str(), &sStat) == 0) { CPLJSONDocument oDocGroup; diff --git a/frmts/zarr/zarr_v2_array.cpp b/frmts/zarr/zarr_v2_array.cpp index 399890c27aa7..7b10cc06c29d 100644 --- a/frmts/zarr/zarr_v2_array.cpp +++ b/frmts/zarr/zarr_v2_array.cpp @@ -127,8 +127,9 @@ void ZarrV2Array::Flush() CPLJSONDocument oDoc; oDoc.SetRoot(oAttrs); - const std::string osAttrFilename = CPLFormFilename( - CPLGetDirname(m_osFilename.c_str()), ".zattrs", nullptr); + const std::string osAttrFilename = + CPLFormFilenameSafe(CPLGetDirnameSafe(m_osFilename.c_str()).c_str(), + ".zattrs", nullptr); oDoc.Save(osAttrFilename); m_poSharedResource->SetZMetadataItem(osAttrFilename, oAttrs); } @@ -987,8 +988,8 @@ std::string ZarrV2Array::BuildTileFilename(const uint64_t *tileIndices) const } } - return CPLFormFilename(CPLGetDirnameSafe(m_osFilename.c_str()).c_str(), - osFilename.c_str(), nullptr); + return CPLFormFilenameSafe(CPLGetDirnameSafe(m_osFilename.c_str()).c_str(), + osFilename.c_str(), nullptr); } /************************************************************************/ @@ -997,7 +998,7 @@ std::string ZarrV2Array::BuildTileFilename(const uint64_t *tileIndices) const std::string ZarrV2Array::GetDataDirectory() const { - return std::string(CPLGetDirnameSafe(m_osFilename.c_str())); + return CPLGetDirnameSafe(m_osFilename.c_str()); } /************************************************************************/ @@ -1328,8 +1329,9 @@ ZarrV2Group::LoadArray(const std::string &osArrayName, if (!bLoadedFromZMetadata) { CPLJSONDocument oDoc; - const std::string osZattrsFilename(CPLFormFilename( - CPLGetDirname(osZarrayFilename.c_str()), ".zattrs", nullptr)); + const std::string osZattrsFilename(CPLFormFilenameSafe( + CPLGetDirnameSafe(osZarrayFilename.c_str()).c_str(), ".zattrs", + nullptr)); CPLErrorStateBackuper oErrorStateBackuper(CPLQuietErrorHandler); if (oDoc.Load(osZattrsFilename)) { diff --git a/ogr/ogrsf_frmts/gmlas/ogrgmlasxsdcache.cpp b/ogr/ogrsf_frmts/gmlas/ogrgmlasxsdcache.cpp index 8a1478c1b7a4..2e0780def723 100644 --- a/ogr/ogrsf_frmts/gmlas/ogrgmlasxsdcache.cpp +++ b/ogr/ogrsf_frmts/gmlas/ogrgmlasxsdcache.cpp @@ -268,12 +268,12 @@ VSILFILE *GMLASXSDCache::Open(const std::string &osResource, STARTS_WITH(osResourceModified.c_str(), "..\\")) && !osBasePathModified.empty()) { - osBasePathModified = CPLGetDirname(osBasePathModified.c_str()); + osBasePathModified = CPLGetDirnameSafe(osBasePathModified.c_str()); osResourceModified = osResourceModified.substr(3); } - osOutFilename = CPLFormFilename(osBasePathModified.c_str(), - osResourceModified.c_str(), nullptr); + osOutFilename = CPLFormFilenameSafe( + osBasePathModified.c_str(), osResourceModified.c_str(), nullptr); } CPLDebug("GMLAS", "Resolving %s (%s) to %s", osResource.c_str(), diff --git a/ogr/ogrsf_frmts/libkml/ogrlibkmlfeaturestyle.cpp b/ogr/ogrsf_frmts/libkml/ogrlibkmlfeaturestyle.cpp index f730708815ee..dfba6f4fbdd8 100644 --- a/ogr/ogrsf_frmts/libkml/ogrlibkmlfeaturestyle.cpp +++ b/ogr/ogrsf_frmts/libkml/ogrlibkmlfeaturestyle.cpp @@ -247,8 +247,9 @@ void kml2featurestyle(FeaturePtr poKmlFeature, OGRLIBKMLDataSource *poOgrDS, } else if (CPLIsFilenameRelative(osUrlTmp.c_str())) { - osUrlTmp = CPLFormFilename( - CPLGetDirname(poOgrDS->GetDescription()), + osUrlTmp = CPLFormFilenameSafe( + CPLGetDirnameSafe(poOgrDS->GetDescription()) + .c_str(), osUrlTmp.c_str(), nullptr); } CPLDebug("LIBKML", "Trying to resolve style %s", diff --git a/ogr/ogrsf_frmts/miramon/ogrmiramondatasource.cpp b/ogr/ogrsf_frmts/miramon/ogrmiramondatasource.cpp index 31011c337432..5a211ac86297 100644 --- a/ogr/ogrsf_frmts/miramon/ogrmiramondatasource.cpp +++ b/ogr/ogrsf_frmts/miramon/ogrmiramondatasource.cpp @@ -157,7 +157,7 @@ OGRMiraMonDataSource::ICreateLayer(const char *pszLayerName, // Checking that the folder where to write exists const std::string osDestFolder = - CPLGetDirname(osFullMMLayerName.c_str()); + CPLGetDirnameSafe(osFullMMLayerName.c_str()); if (!STARTS_WITH(osDestFolder.c_str(), "/vsimem")) { VSIStatBufL sStat; diff --git a/ogr/ogrsf_frmts/miramon/ogrmiramonlayer.cpp b/ogr/ogrsf_frmts/miramon/ogrmiramonlayer.cpp index 24523402488b..184864f463e1 100644 --- a/ogr/ogrsf_frmts/miramon/ogrmiramonlayer.cpp +++ b/ogr/ogrsf_frmts/miramon/ogrmiramonlayer.cpp @@ -3001,36 +3001,51 @@ void OGRMiraMonLayer::AddToFileList(CPLStringList &oFileList) CPLStrlcpy(szAuxFile, osBaseArcName.c_str(), MM_CPL_PATH_BUF_SIZE); CPLStrlcat(szAuxFile, (pszMMExt[0] == 'p') ? "A.rel" : "A.REL", MM_CPL_PATH_BUF_SIZE); - oFileList.AddStringDirectly(VSIGetCanonicalFilename(CPLFormFilename( - CPLGetDirname(szCompleteArcFileName), szAuxFile, nullptr))); + oFileList.AddStringDirectly(VSIGetCanonicalFilename( + CPLFormFilenameSafe( + CPLGetDirnameSafe(szCompleteArcFileName).c_str(), szAuxFile, + nullptr) + .c_str())); // FILE_NAME_WITHOUT_EXTENSION.arc --> FILE_NAME_WITHOUT_EXTENSION + A.dbf CPLStrlcpy(szAuxFile, osBaseArcName.c_str(), MM_CPL_PATH_BUF_SIZE); CPLStrlcat(szAuxFile, (pszMMExt[0] == 'p') ? "A.dbf" : "A.DBF", MM_CPL_PATH_BUF_SIZE); - oFileList.AddStringDirectly(VSIGetCanonicalFilename(CPLFormFilename( - CPLGetDirname(szCompleteArcFileName), szAuxFile, nullptr))); + oFileList.AddStringDirectly(VSIGetCanonicalFilename( + CPLFormFilenameSafe( + CPLGetDirnameSafe(szCompleteArcFileName).c_str(), szAuxFile, + nullptr) + .c_str())); // FILE_NAME_WITHOUT_EXTENSION.arc --> FILE_NAME_WITHOUT_EXTENSION + .nod CPLStrlcpy(szAuxFile, osBaseArcName.c_str(), MM_CPL_PATH_BUF_SIZE); CPLStrlcat(szAuxFile, (pszMMExt[0] == 'p') ? ".nod" : ".NOD", MM_CPL_PATH_BUF_SIZE); - oFileList.AddStringDirectly(VSIGetCanonicalFilename(CPLFormFilename( - CPLGetDirname(szCompleteArcFileName), szAuxFile, nullptr))); + oFileList.AddStringDirectly(VSIGetCanonicalFilename( + CPLFormFilenameSafe( + CPLGetDirnameSafe(szCompleteArcFileName).c_str(), szAuxFile, + nullptr) + .c_str())); // FILE_NAME_WITHOUT_EXTENSION.arc --> FILE_NAME_WITHOUT_EXTENSION + N.rel CPLStrlcpy(szAuxFile, osBaseArcName.c_str(), MM_CPL_PATH_BUF_SIZE); CPLStrlcat(szAuxFile, (pszMMExt[0] == 'p') ? "N.rel" : "N.REL", MM_CPL_PATH_BUF_SIZE); - oFileList.AddStringDirectly(VSIGetCanonicalFilename(CPLFormFilename( - CPLGetDirname(szCompleteArcFileName), szAuxFile, nullptr))); + oFileList.AddStringDirectly(VSIGetCanonicalFilename( + CPLFormFilenameSafe( + CPLGetDirnameSafe(szCompleteArcFileName).c_str(), szAuxFile, + nullptr) + .c_str())); // FILE_NAME_WITHOUT_EXTENSION.arc --> FILE_NAME_WITHOUT_EXTENSION + N.dbf CPLStrlcpy(szAuxFile, osBaseArcName.c_str(), MM_CPL_PATH_BUF_SIZE); CPLStrlcat(szAuxFile, (pszMMExt[0] == 'p') ? "N.dbf" : "N.DBF", MM_CPL_PATH_BUF_SIZE); - oFileList.AddStringDirectly(VSIGetCanonicalFilename(CPLFormFilename( - CPLGetDirname(szCompleteArcFileName), szAuxFile, nullptr))); + oFileList.AddStringDirectly(VSIGetCanonicalFilename( + CPLFormFilenameSafe( + CPLGetDirnameSafe(szCompleteArcFileName).c_str(), szAuxFile, + nullptr) + .c_str())); } CPLFree(pszMMExt); }