Skip to content

Commit 05d59a1

Browse files
authored
Merge pull request #29273 from vbotbuildovich/backport-pr-29267-v25.3.x-500
[v25.3.x] bytes: ensure `iobuf::operator<=>(...)` is an unsigned byte-wise comparison
2 parents 071198d + a9291d3 commit 05d59a1

File tree

3 files changed

+4
-1
lines changed

3 files changed

+4
-1
lines changed

src/v/bytes/iobuf.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ std::strong_ordering iobuf::operator<=>(const iobuf& o) const {
130130
constexpr static size_t max_byte_for_byte_cmp = 4;
131131
const auto n = std::min({lhs.size(), rhs.size(), max_byte_for_byte_cmp});
132132
for (size_t i = 0; i < n; ++i) {
133-
const auto cmp = lhs[i] <=> rhs[i];
133+
const auto cmp = static_cast<unsigned char>(lhs[i])
134+
<=> static_cast<unsigned char>(rhs[i]);
134135
if (cmp != std::strong_ordering::equal) {
135136
return cmp;
136137
}

src/v/bytes/iobuf.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ class iobuf {
252252
bool operator==(const iobuf&) const;
253253
bool operator<(const iobuf&) const;
254254
bool operator!=(const iobuf&) const;
255+
/// Does an unsigned byte-wise comparison between this iobuf and the other.
255256
std::strong_ordering operator<=>(const iobuf&) const;
256257

257258
bool operator==(std::string_view) const;

src/v/bytes/tests/iobuf_tests.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ SEASTAR_THREAD_TEST_CASE(test_lt) {
5151
BOOST_CHECK_LT(iobuf::from(""), iobuf::from("cat"));
5252
BOOST_CHECK_LT(iobuf::from("cat"), iobuf::from("dog"));
5353
BOOST_CHECK_LT(iobuf::from("cat"), iobuf::from("catastrophe"));
54+
BOOST_CHECK_LT(iobuf::from("\x01"), iobuf::from("\xFF"));
5455
BOOST_CHECK_EQUAL(false, iobuf::from("cat") < iobuf::from("cat"));
5556
BOOST_CHECK_EQUAL(false, iobuf{} < iobuf{});
5657
BOOST_CHECK(std::strong_ordering::equal == (iobuf{} <=> iobuf{}));

0 commit comments

Comments
 (0)