The length passed with a buffer is the size of the pointer to it
What it finds
memset(p, 0, sizeof(p)), where p is a pointer: the length is the size of the pointer, not of what it points to, so only the first 4 or 8 bytes are written. The size of *p or of the buffer was meant.
The function must be the C library's: the file neither declares it nor defines it as a macro. The pointer must be declared in the file as a pointer, not as an array, and not as a pointer to a pointer, for which the two sizes agree.
From the rule's source, sizeof_pointer_length.rs.
#include <stdio.h>#include <string.h> struct conf { int a; int b;}; void reset(struct conf *c, char *name, const char *src, char **list, void *raw, int n){ char buf[32]; memset(c, 0, sizeof(c));tx0 reports: sizeof(c) is the size of the pointer, not of what c points to memcpy(name, src, sizeof name);tx0 reports: sizeof(name) is the size of the pointer snprintf(name, sizeof(name), "%d", n);tx0 reports: sizeof(name) is the size of the pointer memset(raw, 0, sizeof(raw));tx0 reports: sizeof(raw) is the size of the pointer memset(c, 0, sizeof(*c)); memset(buf, 0, sizeof(buf)); memset(list, 0, sizeof(list)); memcpy(&c, &raw, sizeof(c)); memset(name, 0, sizeof(src)); strncpy(buf, src, sizeof(buf));} 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:
[rules]
"tx0/c:sizeof-pointer-length" = "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:sizeof-pointer-length] reason="..."tx0 explain tx0/c:sizeof-pointer-length shows the same in the terminal. Found a false positive? Report it.