From 3123de7717461f2fa5aa8a8844190f7dddef307e Mon Sep 17 00:00:00 2001 From: Joel Rosdahl Date: Wed, 22 Oct 2025 22:15:23 +0200 Subject: [PATCH] fix: Fix comparison of empty Bytes objects --- src/ccache/util/bytes.hpp | 6 ++++-- unittest/test_util_bytes.cpp | 7 ++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/ccache/util/bytes.hpp b/src/ccache/util/bytes.hpp index fba14d61..c103ed22 100644 --- a/src/ccache/util/bytes.hpp +++ b/src/ccache/util/bytes.hpp @@ -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 diff --git a/unittest/test_util_bytes.cpp b/unittest/test_util_bytes.cpp index 35ca9ff4..d90120f5 100644 --- a/unittest/test_util_bytes.cpp +++ b/unittest/test_util_bytes.cpp @@ -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") { -- 2.47.3