A constant size given with an array is larger than the array
What it finds
char buf[16]; memset(buf, 0, 32); or fgets(buf, 64, f): the size passed with the buffer is a constant larger than the array, so the function reads or writes past its end.
The array must be a variable, not a parameter, declared in the file with a literal length and with elements of a character type, so that the length counts bytes; the size must be written with literals.
From the rule's source, constant_size_exceeds_array.rs.
#include <stdio.h>#include <string.h> void fill(FILE *f, char param[8]){ char buf[16]; int wide[16]; memset(buf, 0, 32);tx0 reports: memset is given a size of 32 for buf, which holds 16 bytes fgets(buf, 64, f);tx0 reports: fgets is given a size of 64 for buf, which holds 16 bytes memset(buf, 0, 16); memset(wide, 0, 64); memset(param, 0, 32);} Turn it on, off or suppress it
The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:
[rules]
"tx0/c:constant-size-exceeds-array" = "off"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/c:constant-size-exceeds-array] reason="..."tx0 explain tx0/c:constant-size-exceeds-array shows the same in the terminal. Found a false positive? Report it.