A std::unique_ptr or std::shared_ptr of a single object takes an array made with new[], and frees it with delete

tx0/cpp:smart-pointer-array-mismatchdefaulterrorreliability/memory-safetydepth fastbug, cwe-762

What it finds

std::unique_ptr<int> p(new int[n]); frees the array with delete, not delete[], which is undefined behaviour. The array form, std::unique_ptr<int[]>, frees with delete[]; a std::vector is usually better still.

From the rule's source, smart_pointer_array_mismatch.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:smart-pointer-array-mismatch" = "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:smart-pointer-array-mismatch] reason="..."

tx0 explain tx0/cpp:smart-pointer-array-mismatch shows the same in the terminal. Found a false positive? Report it.