memset is given a fill value that does not fit in a byte

tx0/c:memset-value-truncateddefaultwarningbug

What it finds

memset(buf, 1000, n) or memset(a, 0x1234, n): memset converts the value to unsigned char and fills every byte with it, so only the lowest byte is used. Filling an array of wider elements with a value takes a loop.

The value must be a constant written with literals, larger than 255 or smaller than -128.

From the rule's source, memset_value_truncated.rs.

Example from the rule's tests
#include <string.h> void fill(int *a, unsigned long n){  memset(a, 1000, n);tx0 reports: memset fills bytes, so only the lowest byte of 1000 is used  memset(a, 0xff, n);  memset(a, -1, n);}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

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:

tx0.toml
[rules]
"tx0/c:memset-value-truncated" = "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:memset-value-truncated] reason="..."

tx0 explain tx0/c:memset-value-truncated shows the same in the terminal. Found a false positive? Report it.