A variable is defined at file scope without const, so any code that sees it can change it
What it finds
int retry_count = 3; at file scope: state shared by every function of the file, and of the program unless it is static, can change anywhere, which makes the code hard to reason about, to test and to run in threads.
From the rule's source, mutable_global_variable.rs.
static const int limit = 10;int retry_count = 3;tx0 reports: retry_count is a variable at file scope that any code can changestatic const char *const names[] = { "a", "b" }; int next(void){ return retry_count + limit + (names[0] != 0);} Turn it on, off or suppress it
The rule runs from the all tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/c:mutable-global-variable" = "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:mutable-global-variable] reason="..."tx0 explain tx0/c:mutable-global-variable shows the same in the terminal. Found a false positive? Report it.