]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
fix: Make src/ccache.cpp cacheable by ccache itself
authorJoel Rosdahl <joel@rosdahl.net>
Sun, 9 Jan 2022 21:13:02 +0000 (22:13 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Mon, 10 Jan 2022 21:22:00 +0000 (22:22 +0100)
“.incbin” should not be present verbatim in the source code since that
makes ccache consider the code uncacheable.

Regression in 2d2de82bb9231b981b40486b093a2c0002200c40.

src/ccache.cpp

index 422d97695efcf613406ac4b50d8fff473a7c3ac3..939189b3caef9632f4f67c8896c0c952124f4eb4 100644 (file)
@@ -1,5 +1,5 @@
 // Copyright (C) 2002-2007 Andrew Tridgell
-// Copyright (C) 2009-2021 Joel Rosdahl and other contributors
+// Copyright (C) 2009-2022 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
@@ -460,6 +460,10 @@ process_preprocessed_file(Context& ctx, Hash& hash, const std::string& path)
       "# 31 \"<command-line>\"\n";
     static const string_view hash_32_command_line_2_newline =
       "# 32 \"<command-line>\" 2\n";
+    // Note: Intentionally not using the string form to avoid false positive
+    // match by ccache itself.
+    static const char incbin_prefix[] = {
+      '.', 'i', 'n', 'c', 'b', 'i', 'n', ' '};
 
     // Check if we look at a line containing the file name of an included file.
     // At least the following formats exist (where N is a positive integer):
@@ -572,8 +576,8 @@ process_preprocessed_file(Context& ctx, Hash& hash, const std::string& path)
           Statistic::could_not_use_precompiled_header);
       }
       p = q; // Everything of interest between p and q has been hashed now.
-    } else if (strncmp(q, ".incbin \\\"", 10) == 0
-               || strncmp(q, ".incbin \"", 9) == 0) {
+    } else if (strncmp(q, incbin_prefix, sizeof(incbin_prefix)) == 0
+               && (q[8] == '"' || (q[8] == '\\' && q[9] == '"'))) {
       // An assembler .inc bin (without the space) statement, which could be
       // part of inline assembly, refers to an external file. If the file
       // changes, the hash should change as well, but finding out what file to