mirror of
https://github.com/webmproject/libwebp.git
synced 2025-08-28 23:03:20 +02:00
Add fbounds-safety annotations for count
.
Reasoning: The function `NextTableBitSize` is only called by `BuildHuffmanTable` (src/utils/huffman_utils.c:196). In `BuildHuffmanTable`, `count` is defined as a local array `int count[MAX_ALLOWED_CODE_LENGTH + 1]` (line 93). This array decays to a pointer when passed to `NextTableBitSize`. The maximum index accessed within `NextTableBitSize` is `MAX_ALLOWED_CODE_LENGTH - 1` (line 75, inside a loop where `len` starts <= `MAX_ALLOWED_CODE_LENGTH` and increments up to `MAX_ALLOWED_CODE_LENGTH`). Since the caller provides an array of size `MAX_ALLOWED_CODE_LENGTH + 1` and the accesses are within bounds, the `count` parameter in `NextTableBitSize` is annotated with `WEBP_COUNTED_BY(MAX_ALLOWED_CODE_LENGTH + 1)`. This resolves the compiler error. Bug: 432511821 Change-Id: I29a55dd7f09c04aa3a2394996cf0e123d985fcd0
This commit is contained in:
@@ -68,8 +68,9 @@ static WEBP_INLINE void ReplicateValue(HuffmanCode* table, int step, int end,
|
||||
// Returns the table width of the next 2nd level table. count is the histogram
|
||||
// of bit lengths for the remaining symbols, len is the code length of the next
|
||||
// processed symbol
|
||||
static WEBP_INLINE int NextTableBitSize(const int* const count, int len,
|
||||
int root_bits) {
|
||||
static WEBP_INLINE int NextTableBitSize(
|
||||
const int* const WEBP_COUNTED_BY(MAX_ALLOWED_CODE_LENGTH + 1) count,
|
||||
int len, int root_bits) {
|
||||
int left = 1 << (len - root_bits);
|
||||
while (len < MAX_ALLOWED_CODE_LENGTH) {
|
||||
left -= count[len];
|
||||
|
Reference in New Issue
Block a user