memset fills memory with the character '0' where the byte zero was probably meant

tx0/c:memset-character-zerorecommendedwarningreliability/memory-safetydepth fastbug

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.

Example from the rule's tests
#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);}
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 from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:

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.