A library function that returns a pointer to shared static storage is called
What it finds
strtok, localtime, gmtime, ctime, asctime, getpwnam, gethostbyname and the like keep their result or their state in one static buffer, which the next call from anywhere overwrites; in threads, or with two uses at once, results are mixed up. The _r variants take a buffer of the caller's.
From the rule's source, non_reentrant_function.rs.
#include <string.h>#include <time.h> void split(char *line, time_t t){ char *word = strtok(line, " ");tx0 reports: strtok keeps its result in static storage struct tm *tm = localtime(&t);tx0 reports: localtime keeps its result in static storage (void)word; (void)tm;} 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:
[rules]
"tx0/c:non-reentrant-function" = "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:non-reentrant-function] reason="..."tx0 explain tx0/c:non-reentrant-function shows the same in the terminal. Found a false positive? Report it.