@@ -728,17 +728,25 @@ ResultType Get::ApplyTo(Overflow ov, const string* bitfield) {
728
728
const size_t offset = attr_.offset ;
729
729
auto last_byte_offset = GetByteIndex (attr_.offset + attr_.encoding_bit_size - 1 );
730
730
731
+ if (GetByteIndex (offset) >= total_bytes) {
732
+ return 0 ;
733
+ }
734
+
735
+ const string* result_str = bitfield;
736
+ string buff;
731
737
uint32_t lsb = attr_.offset + attr_.encoding_bit_size - 1 ;
732
- if (last_byte_offset > total_bytes) {
733
- return {};
738
+ if (last_byte_offset >= total_bytes) {
739
+ buff = *bitfield;
740
+ buff.resize (last_byte_offset + 1 , 0 );
741
+ result_str = &buff;
734
742
}
735
743
736
744
const bool is_negative =
737
745
CheckBitStatus (GetByteValue (bytes, offset), GetNormalizedBitIndex (offset));
738
746
739
747
int64_t result = 0 ;
740
748
for (size_t i = 0 ; i < attr_.encoding_bit_size ; ++i) {
741
- uint8_t byte{GetByteValue (bytes , lsb)};
749
+ uint8_t byte{GetByteValue (*result_str , lsb)};
742
750
int32_t index = GetNormalizedBitIndex (lsb);
743
751
int64_t old_bit = CheckBitStatus (byte, index );
744
752
result |= old_bit << i;
@@ -830,10 +838,11 @@ ResultType IncrBy::ApplyTo(Overflow ov, string* bitfield) {
830
838
string& bytes = *bitfield;
831
839
Get get (attr_);
832
840
auto res = get.ApplyTo (ov, &bytes);
841
+ const int32_t total_bytes = static_cast <int32_t >(bytes.size ());
842
+ auto last_byte_offset = GetByteIndex (attr_.offset + attr_.encoding_bit_size - 1 );
833
843
834
- if (!res) {
835
- Set set (attr_, incr_value_);
836
- return set.ApplyTo (ov, &bytes);
844
+ if (last_byte_offset >= total_bytes) {
845
+ bytes.resize (last_byte_offset + 1 , 0 );
837
846
}
838
847
839
848
if (!HandleOverflow (ov, &*res)) {
0 commit comments