Skip to content

Commit

Permalink
Fix Coverity Scan warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed Jan 19, 2025
1 parent 607bec8 commit 93878ec
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
4 changes: 3 additions & 1 deletion autotest/cpp/test_marching_squares_polygon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

{
Expand Down
13 changes: 6 additions & 7 deletions port/cpl_path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<size_t>(pszQuestionMark - pszPath);
nLenPath = nSuffixPos;
nLenPath = pszQuestionMark - pszPath;
}
pszAddedPathSep = "/";
}
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 93878ec

Please sign in to comment.