calloc is given the size of an element first and the number of elements second

tx0/c:calloc-size-firststrictwarningmaintainability/complexitydepth fastsmell

What it finds

calloc(sizeof(struct item), count): calloc takes the number of elements first and the size of one second. The product is the same, but the order is what tools that check bounds read, and it says what the call allocates. The fix swaps the arguments.

The first argument must be a sizeof and the second neither a sizeof nor a constant.

From the rule's source, calloc_size_first.rs.

Example from the rule's tests
#include <stdlib.h> struct item { int v; }; struct item *make(size_t count){  struct item *a = calloc(sizeof(struct item), count);tx0 reports: the size of an element comes first here  struct item *b = calloc(count, sizeof(struct item));  struct item *c = calloc(sizeof(struct item), 1);  free(a);  free(c);  return b;}
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 strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/c:calloc-size-first" = "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:calloc-size-first] reason="..."

tx0 explain tx0/c:calloc-size-first shows the same in the terminal. Found a false positive? Report it.