A cast turns a pointer to const data into a pointer through which the data can be written

tx0/c:cast-drops-conststrictwarningmaintainability/designdepth fastsmell, cwe-704

What it finds

char *s = (char *)name; with const char *name: the cast removes const from what the pointer points to, so a write through the result compiles, and is undefined if the object really is constant, as a string literal is.

The operand must be a variable declared in the file as a pointer to a const type, and the cast to a pointer to the same kind of type without const. Casts to void * are left alone, since they mostly pass the pointer on to functions such as free.

From the rule's source, cast_drops_const.rs.

Example from the rule's tests
#include <stdlib.h> char *unconst(const char *name, char *plain){  char *s = (char *)name;tx0 reports: this cast drops the const of what name points to  free((void *)name);  return s + (plain - (char *)plain);}
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:cast-drops-const" = "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:cast-drops-const] reason="..."

tx0 explain tx0/c:cast-drops-const shows the same in the terminal. Found a false positive? Report it.