summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Rosdahl <joel@rosdahl.net>2022-11-03 20:56:32 +0100
committerJoel Rosdahl <joel@rosdahl.net>2022-11-03 22:10:47 +0100
commit91112ead917c96b533685701de64d025bd00769d (patch)
treef7c9ef86596cb71728131fb8e9c342410cfbfa66
parent072cf36daaebad30dfa66c63991efb8b9e629033 (diff)
downloadccache-91112ead917c96b533685701de64d025bd00769d.tar.gz
fix: Fix parsing of sloppiness with trailing delimiter
-rw-r--r--src/Config.cpp11
-rw-r--r--unittest/test_Config.cpp5
2 files changed, 7 insertions, 9 deletions
diff --git a/src/Config.cpp b/src/Config.cpp
index 3cec222f..275cdcb2 100644
--- a/src/Config.cpp
+++ b/src/Config.cpp
@@ -28,6 +28,7 @@
#include <core/types.hpp>
#include <core/wincompat.hpp>
#include <fmtmacros.hpp>
+#include <util/Tokenizer.hpp>
#include <util/expected.hpp>
#include <util/file.hpp>
#include <util/path.hpp>
@@ -280,13 +281,9 @@ parse_compiler_type(const std::string& value)
core::Sloppiness
parse_sloppiness(const std::string& value)
{
- size_t start = 0;
- size_t end = 0;
core::Sloppiness result;
- while (end != std::string::npos) {
- end = value.find_first_of(", ", start);
- std::string token =
- util::strip_whitespace(value.substr(start, end - start));
+
+ for (const auto token : util::Tokenizer(value, ", ")) {
if (token == "clang_index_store") {
result.enable(core::Sloppy::clang_index_store);
} else if (token == "file_stat_matches") {
@@ -314,8 +311,8 @@ parse_sloppiness(const std::string& value)
} else if (token == "time_macros") {
result.enable(core::Sloppy::time_macros);
} // else: ignore unknown value for forward compatibility
- start = value.find_first_not_of(", ", end);
}
+
return result;
}
diff --git a/unittest/test_Config.cpp b/unittest/test_Config.cpp
index 559cc1b1..70a66dd2 100644
--- a/unittest/test_Config.cpp
+++ b/unittest/test_Config.cpp
@@ -135,7 +135,8 @@ TEST_CASE("Config::update_from_file")
"run_second_cpp = false\n"
"sloppiness = time_macros ,include_file_mtime"
" include_file_ctime,file_stat_matches,file_stat_matches_ctime,pch_defines"
- " , no_system_headers,system_headers,clang_index_store,ivfsoverlay,gcno_cwd\n"
+ " , no_system_headers,system_headers,clang_index_store,ivfsoverlay,"
+ " gcno_cwd,\n"
"stats = false\n"
"temporary_dir = ${USER}_foo\n"
"umask = 777"); // Note: no newline.
@@ -424,7 +425,7 @@ TEST_CASE("Config::visit_items")
"run_second_cpp = false\n"
"sloppiness = include_file_mtime, include_file_ctime, time_macros,"
" file_stat_matches, file_stat_matches_ctime, pch_defines, system_headers,"
- " clang_index_store, ivfsoverlay, gcno_cwd\n"
+ " clang_index_store, ivfsoverlay, gcno_cwd \n"
"stats = false\n"
"stats_log = sl\n"
"temporary_dir = td\n"