]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
fix: Work around problem with GCC in util::ends_with
authorJoel Rosdahl <joel@rosdahl.net>
Mon, 6 Jun 2022 18:46:09 +0000 (20:46 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Mon, 6 Jun 2022 19:36:39 +0000 (21:36 +0200)
The util::ends_with implementation is taken directly from the
implementation suggestion in the C++20 standard, but it produces a
stringop-overread warning with GCC 11.2. There's either some subtle
aspect to this that I don't understand or a compiler bug, but let's work
around it by tweaking the implementation.

Closes #1082.

src/util/string.hpp

index 54b0e68abdd5536efb8c7bd3b425eaf89d8456e2..4e17eaebc9e793d71b69ff7e8a1baabc2351b623 100644 (file)
@@ -120,9 +120,7 @@ inline bool
 ends_with(const std::string_view string, const std::string_view suffix)
 {
   return string.length() >= suffix.length()
-         && string.compare(
-              string.length() - suffix.length(), std::string_view::npos, suffix)
-              == 0;
+         && string.substr(string.length() - suffix.length()) == suffix;
 }
 
 template<typename T>