memset, memcpy or memmove writes over an object of a class with virtual functions or with string or container members

tx0/cpp:memset-on-class-objectdefaulterrorreliability/memory-safetydepth fastbug

What it finds

Such objects are not plain bytes: overwriting them destroys the pointer to the virtual table or the pointers inside the members, and copying them byte by byte shares heap memory between two owners. Assignment, constructors or std::fill work on them correctly. The class must be defined in the file.

From the rule's source, memset_on_class_object.rs.

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:

tx0.toml
[rules]
"tx0/cpp:memset-on-class-object" = "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/cpp:memset-on-class-object] reason="..."

tx0 explain tx0/cpp:memset-on-class-object shows the same in the terminal. Found a false positive? Report it.