From 93878ec4bd32183b614f6fd1243ba9a2a5b90a57 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Sun, 19 Jan 2025 23:47:10 +0100 Subject: [PATCH] Fix Coverity Scan warnings --- autotest/cpp/test_marching_squares_polygon.cpp | 4 +++- port/cpl_path.cpp | 13 ++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/autotest/cpp/test_marching_squares_polygon.cpp b/autotest/cpp/test_marching_squares_polygon.cpp index 6e907cbc2a2b..cbd834fa5a33 100644 --- a/autotest/cpp/test_marching_squares_polygon.cpp +++ b/autotest/cpp/test_marching_squares_polygon.cpp @@ -344,7 +344,9 @@ TEST_F(test_ms_polygon, four_pixels_2) } { EXPECT_EQ(w.polygons_.size(), 2); - EXPECT_EQ(w.polygons_.find(Inf)->second.size(), 0); + auto iter = w.polygons_.find(Inf); + ASSERT_TRUE(iter != w.polygons_.end()); + EXPECT_TRUE(iter->second.empty()); } { diff --git a/port/cpl_path.cpp b/port/cpl_path.cpp index e50e46a0eab0..d9064a6f9424 100644 --- a/port/cpl_path.cpp +++ b/port/cpl_path.cpp @@ -720,14 +720,13 @@ std::string CPLFormFilenameSafe(const char *pszPath, const char *pszBasename, pszPath = ""; size_t nLenPath = strlen(pszPath); - size_t nSuffixPos = 0; + const char *pszQuestionMark = nullptr; if (STARTS_WITH_CI(pszPath, "/vsicurl/http")) { - const char *pszQuestionMark = strchr(pszPath, '?'); + pszQuestionMark = strchr(pszPath, '?'); if (pszQuestionMark) { - nSuffixPos = static_cast(pszQuestionMark - pszPath); - nLenPath = nSuffixPos; + nLenPath = pszQuestionMark - pszPath; } pszAddedPathSep = "/"; } @@ -811,16 +810,16 @@ std::string CPLFormFilenameSafe(const char *pszPath, const char *pszBasename, std::string osRes; osRes.reserve(nLenPath + strlen(pszAddedPathSep) + strlen(pszBasename) + strlen(pszAddedExtSep) + strlen(pszExtension) + - (nSuffixPos ? strlen(pszPath + nSuffixPos) : 0)); + (pszQuestionMark ? strlen(pszQuestionMark) : 0)); osRes.assign(pszPath, nLenPath); osRes += pszAddedPathSep; osRes += pszBasename; osRes += pszAddedExtSep; osRes += pszExtension; - if (nSuffixPos) + if (pszQuestionMark) { - osRes += (pszPath + nSuffixPos); + osRes += pszQuestionMark; } return osRes;