memset is called with a length of zero, its last two arguments swapped

tx0/c:memset-swappeddefaultwarningbug

What it finds

memset(p, n, 0): the length is zero, so nothing is written. The value and the length were swapped: memset(p, 0, n) was meant.

The function must be the C library's, and the length the literal 0 with a value that is not one. A fix that swaps the two is offered, but not applied without asking, since it changes what the program does.

From the rule's source, memset_swapped.rs.

Example from the rule's tests
#include <string.h> void clear(char *p, int n){  memset(p, n, 0);tx0 reports: memset writes zero bytes here; n looks like the length  memset(p, sizeof(*p), 0);tx0 reports: sizeof(*p) looks like the length  memset(p, 0, n);  memset(p, 0, 0);  memset(p, 'x', 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-swapped" = "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-swapped] reason="..."

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