Skip to content

Commit dafc668

Browse files
committed
make bitstream not act on prev overflow
1 parent 06a83f7 commit dafc668

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

middleware/src/bitstream.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ int bitstream_add(bitstream_t *bitstream, uint32_t value, size_t num_bits)
1515
return -1; // Error: not enough space in the bitstream
1616
}
1717

18+
bool overflow = false;
1819
if (value >= pow(2, num_bits)) {
19-
bitstream->overflow =
20+
overflow =
2021
true; // Error: value is too large for the number of bits, so set overflow to true.
2122
value = pow(2, num_bits) -
2223
1; // Cap value to the maximum value that can be stored in the number of bits.
@@ -29,11 +30,13 @@ int bitstream_add(bitstream_t *bitstream, uint32_t value, size_t num_bits)
2930
}
3031
}
3132

33+
bitstream->total_bits += num_bits;
34+
3235
if (bitstream->overflow) {
36+
bitstream->overflow = true;
3337
return 1; // Overflow occurred
3438
}
3539

36-
bitstream->total_bits += num_bits;
3740
return 0; // Success
3841
}
3942

0 commit comments

Comments
 (0)