Skip to content

Commit

Permalink
Check correct number of bits for LZC of XOR value. (netdata#18463)
Browse files Browse the repository at this point in the history
  • Loading branch information
vkalintiris authored Sep 4, 2024
1 parent 4fef11d commit fbc99bd
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/libnetdata/gorilla/gorilla.cc
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,11 @@ bool gorilla_writer_write(gorilla_writer_t *gw, uint32_t number)
__atomic_fetch_add(&hdr->nbits, 1, __ATOMIC_RELAXED);

if (!is_xor_lzc_same) {
if (hdr->nbits + 1 >= gw->capacity)
size_t bits_needed = (bit_size<uint32_t>() == 32) ? 5 : 6;
if ((hdr->nbits + bits_needed) >= gw->capacity)
return false;
bit_buffer_write(data, hdr->nbits, xor_lzc, (bit_size<uint32_t>() == 32) ? 5 : 6);
__atomic_fetch_add(&hdr->nbits, (bit_size<uint32_t>() == 32) ? 5 : 6, __ATOMIC_RELAXED);
bit_buffer_write(data, hdr->nbits, xor_lzc, bits_needed);
__atomic_fetch_add(&hdr->nbits, bits_needed, __ATOMIC_RELAXED);
}

// write the bits of the XOR'd value without the LZC prefix
Expand Down

0 comments on commit fbc99bd

Please sign in to comment.