From 94c59d9d97469a19c30e55ec9900a6ea54528a78 Mon Sep 17 00:00:00 2001 From: Philip Rideout Date: Mon, 28 Feb 2022 13:05:40 -0800 Subject: [PATCH] libutils: fix inconsistent hash in StaticString This caused a unit test failure because a StaticString constructed from "make" had a different hash than one constructed from a literal, even though the two strings were lexigraphically equivalent. --- libs/utils/include/utils/CString.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/utils/include/utils/CString.h b/libs/utils/include/utils/CString.h index 29a3fd29da..1d2e421a9f 100644 --- a/libs/utils/include/utils/CString.h +++ b/libs/utils/include/utils/CString.h @@ -86,7 +86,7 @@ public: constexpr StaticString(StringLiteral const& other) noexcept // NOLINT(google-explicit-constructor) : mString(other), mLength(size_type(N - 1)), - mHash(computeHash(other, N)) { + mHash(computeHash(other, N - 1)) { // we rely on inlining for computeHash. It would be nice to do this with constexpr // instead, but unfortunately 'other' is not constexpr once a parameter. } @@ -98,7 +98,7 @@ public: mLength = size_type(N - 1); // we rely on inlining for computeHash. It would be nice to do this with constexpr // instead, but unfortunately 'other' is not constexpr once a parameter. - mHash = computeHash(other, N); + mHash = computeHash(other, N - 1); return *this; }