fix: ubsan, EMPTY_STRING_REF constant

This commit is contained in:
myrrc 2020-07-29 01:08:09 +03:00
parent cf696afd4c
commit 0f5b089270

View File

@ -45,9 +45,11 @@ struct StringRef
constexpr explicit operator std::string_view() const { return {data, size}; }
};
/// Holds {nullptr, 0};
/// Here constexpr doesn't implicate inline, see https://www.viva64.com/en/w/v1043/
constexpr const inline StringRef EMPTY_STRING_REF{};
/// nullptr can't be used because the StringRef values are used in SipHash's pointer arithmetics
/// and the UBSan thinks that something like nullptr + 8 is UB.
constexpr const inline char empty_string_ref_addr{};
constexpr const inline StringRef EMPTY_STRING_REF{&empty_string_ref_addr, 0};
using StringRefs = std::vector<StringRef>;