]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
fix: Fix comparison of empty Bytes objects
authorJoel Rosdahl <joel@rosdahl.net>
Wed, 22 Oct 2025 20:15:23 +0000 (22:15 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Sat, 25 Oct 2025 10:03:27 +0000 (12:03 +0200)
src/ccache/util/bytes.hpp
unittest/test_util_bytes.cpp

index fba14d61fa09915f02604d9779341c5778e2f7de..c103ed22a4309a1a1c7d6ee2c692980490d5afb5 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2022-2024 Joel Rosdahl and other contributors
+// Copyright (C) 2022-2025 Joel Rosdahl and other contributors
 //
 // See doc/authors.adoc for a complete list of contributors.
 //
@@ -136,7 +136,9 @@ Bytes::operator==(const Bytes& other) const noexcept
 {
   return this == &other
          || (m_size == other.m_size
-             && std::memcmp(m_data.get(), other.m_data.get(), m_size) == 0);
+             && (m_size == 0
+                 || std::memcmp(m_data.get(), other.m_data.get(), m_size)
+                      == 0));
 }
 
 inline bool
index 35ca9ff46efd1e1c5d16dacc329b9dafd3688610..d90120f5a8d858eef861b096f038122c91d10310 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2021-2024 Joel Rosdahl and other contributors
+// Copyright (C) 2021-2025 Joel Rosdahl and other contributors
 //
 // See doc/authors.adoc for a complete list of contributors.
 //
@@ -167,6 +167,11 @@ TEST_CASE("Basics")
     Bytes bytes4("xyz", 3);
     CHECK(bytes4 != bytes1);
     CHECK(!(bytes4 == bytes1));
+
+    Bytes empty1;
+    Bytes empty2;
+    CHECK(empty1 == empty2);
+    CHECK(!(empty1 != empty2));
   }
   SUBCASE("Begin")
   {