mirror of
https://github.com/dragonflydb/dragonfly.git
synced 2025-05-11 10:25:47 +02:00
fix: bitops_family crash fixed
This commit is contained in:
parent
680722d8ff
commit
2c3959b066
2 changed files with 18 additions and 1 deletions
|
@ -138,7 +138,11 @@ constexpr int32_t GetByteIndex(uint32_t offset) noexcept {
|
|||
}
|
||||
|
||||
uint8_t GetByteValue(string_view str, uint32_t offset) {
|
||||
return static_cast<uint8_t>(str[GetByteIndex(offset)]);
|
||||
int32_t byte_index = GetByteIndex(offset);
|
||||
if (byte_index >= static_cast<int32_t>(str.size())) {
|
||||
return 0;
|
||||
}
|
||||
return static_cast<uint8_t>(str[byte_index]);
|
||||
}
|
||||
|
||||
constexpr bool CheckBitStatus(uint8_t byte, uint32_t offset) {
|
||||
|
|
|
@ -805,4 +805,17 @@ TEST_F(BitOpsFamilyTest, BitFieldOperations) {
|
|||
ASSERT_THAT(Run({"bitfield", "foo", "get", "u1", "15"}), IntArg(1));
|
||||
}
|
||||
|
||||
TEST_F(BitOpsFamilyTest, BitFieldLargeOffset) {
|
||||
Run({"set", "foo", "bar"});
|
||||
|
||||
Run({"bitfield", "foo", "get", "u32", "0", "overflow", "fail", "incrby", "u32", "0",
|
||||
"4294967295"});
|
||||
|
||||
auto resp = Run({"bitfield", "foo", "get", "u32", "4294967295"});
|
||||
EXPECT_EQ(resp, 825276672);
|
||||
|
||||
resp = Run({"bitfield", "foo", "get", "u32", "8589934590"});
|
||||
EXPECT_EQ(resp, 412638336);
|
||||
}
|
||||
|
||||
} // end of namespace dfly
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue