free is given a pointer computed by adding to or subtracting from another pointer
What it finds
free(p + 1): only a pointer that the allocator returned can be given back, and one that points into the middle of a block corrupts the heap.
The argument must be a sum or difference whose left operand the file declares as a pointer, and the function the C library's free.
From the rule's source, free_pointer_offset.rs.
#include <stdlib.h> void release(char *p, int n){ free(p + 1);tx0 reports: free is given a pointer into the middle of a block free(p); free((char *)n + 1);} 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:free-pointer-offset" = "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:free-pointer-offset] reason="..."tx0 explain tx0/c:free-pointer-offset shows the same in the terminal. Found a false positive? Report it.