summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Rosdahl <joel@rosdahl.net>2022-11-09 21:06:05 +0100
committerJoel Rosdahl <joel@rosdahl.net>2022-11-10 13:20:26 +0100
commite031c2170ba9ebeaadf240c22b8fe9f8be13010b (patch)
treefead2246ad508430d4de4a61bb66c9efd3ddad8a
parentfb7ce2f8dd415461439683939da2e3cb5bebdebc (diff)
downloadccache-e031c2170ba9ebeaadf240c22b8fe9f8be13010b.tar.gz
refactor: Avoid changing loop variable in body of for loop
This is to please CodeQL's "For loop variable changed in body" check.
-rw-r--r--src/Util.cpp4
-rw-r--r--src/util/string.cpp4
2 files changed, 6 insertions, 2 deletions
diff --git a/src/Util.cpp b/src/Util.cpp
index bdcc9117..eaac8b95 100644
--- a/src/Util.cpp
+++ b/src/Util.cpp
@@ -438,7 +438,8 @@ expand_environment_variables(const std::string& str)
{
std::string result;
const char* left = str.c_str();
- for (const char* right = left; *right; ++right) {
+ const char* right = left;
+ while (*right) {
if (*right == '$') {
result.append(left, right - left);
@@ -471,6 +472,7 @@ expand_environment_variables(const std::string& str)
left = right + 1;
}
}
+ ++right;
}
result += left;
return result;
diff --git a/src/util/string.cpp b/src/util/string.cpp
index 7f178415..3a03a0be 100644
--- a/src/util/string.cpp
+++ b/src/util/string.cpp
@@ -134,7 +134,8 @@ percent_decode(std::string_view string)
std::string result;
result.reserve(string.size());
- for (size_t i = 0; i < string.size(); ++i) {
+ size_t i = 0;
+ while (i < string.size()) {
if (string[i] != '%') {
result += string[i];
} else if (i + 2 >= string.size() || !std::isxdigit(string[i + 1])
@@ -147,6 +148,7 @@ percent_decode(std::string_view string)
result += ch;
i += 2;
}
+ ++i;
}
return result;