diff --git a/bytes.hh b/bytes.hh index 9d1a0689b9..2999abde01 100644 --- a/bytes.hh +++ b/bytes.hh @@ -84,9 +84,12 @@ struct appending_hash { }; inline int32_t compare_unsigned(bytes_view v1, bytes_view v2) { - auto n = memcmp(v1.begin(), v2.begin(), std::min(v1.size(), v2.size())); + auto size = std::min(v1.size(), v2.size()); + if (size) { + auto n = memcmp(v1.begin(), v2.begin(), size); if (n) { return n; } + } return (int32_t) (v1.size() - v2.size()); } diff --git a/compound_compat.hh b/compound_compat.hh index e8e8b03f1d..8b825e30d3 100644 --- a/compound_compat.hh +++ b/compound_compat.hh @@ -148,8 +148,8 @@ public: _type.begin(k1), _type.end(k1), _type.begin(k2), _type.end(k2), [] (const bytes_view& c1, const bytes_view& c2) -> int { - if (c1.size() != c2.size()) { - return c1.size() < c2.size() ? -1 : 1; + if (c1.size() != c2.size() || !c1.size()) { + return c1.size() < c2.size() ? -1 : c1.size() ? 1 : 0; } return memcmp(c1.begin(), c2.begin(), c1.size()); });