]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
fix: Fix parsing of sloppiness with trailing delimiter
authorJoel Rosdahl <joel@rosdahl.net>
Thu, 3 Nov 2022 19:56:32 +0000 (20:56 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Thu, 3 Nov 2022 21:10:47 +0000 (22:10 +0100)
src/Config.cpp
unittest/test_Config.cpp

index 3cec222f6ed5f2c367fb51f1b6c90a15dcd85ce4..275cdcb29178ba4f1595e9f6270284526d4e151d 100644 (file)
@@ -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;
 }
 
index 559cc1b1a7c59064180371cd870f85ee9311b190..70a66dd28c908a1a9f13aad778a833233613c012 100644 (file)
@@ -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"