memset fills memory with the character '0' where the byte zero was probably meant
What it finds
memset(buf, '0', size): the character '0' is the byte 48, so the buffer is filled with the digit zero rather than cleared; 0 or '\0' clears it.
Buffers of digits are sometimes filled so on purpose, so the rule is not in the default set; the fix, which may change behaviour, writes 0.
From the rule's source, memset_character_zero.rs.
#include <string.h> void clear(char *buf, int n){ memset(buf, '0', n);tx0 reports: '0' is the digit zero memset(buf, 0, n); memset(buf, '\0', n);} Turn it on, off or suppress it
The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/c:memset-character-zero" = "warning"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-character-zero] reason="..."tx0 explain tx0/c:memset-character-zero shows the same in the terminal. Found a false positive? Report it.