Check correct number of bits for LZC of XOR value. (#18463)
vkalintiris committed
Sep 4, 2024 at 11:11 UTC
fbc99bd76a2c9ca8ce18c185631fc60404f09e7c
1 file changed
+4
-3
src/libnetdata/gorilla/gorilla.cc
+4
-3
@@ -162,10 +162,11 @@ bool gorilla_writer_write(gorilla_writer_t *gw, uint32_t number)
162
__atomic_fetch_add(&hdr->nbits, 1, __ATOMIC_RELAXED);
163
164
if (!is_xor_lzc_same) {
165
- if (hdr->nbits + 1 >= gw->capacity)
165
+ size_t bits_needed = (bit_size<uint32_t>() == 32) ? 5 : 6;
166
+ if ((hdr->nbits + bits_needed) >= gw->capacity)
167
return false;
167
- bit_buffer_write(data, hdr->nbits, xor_lzc, (bit_size<uint32_t>() == 32) ? 5 : 6);
168
- __atomic_fetch_add(&hdr->nbits, (bit_size<uint32_t>() == 32) ? 5 : 6, __ATOMIC_RELAXED);
168
+ bit_buffer_write(data, hdr->nbits, xor_lzc, bits_needed);
169
+ __atomic_fetch_add(&hdr->nbits, bits_needed, __ATOMIC_RELAXED);
170
}
171
172
// write the bits of the XOR'd value without the LZC prefix