V627. Consider inspecting the expression. The argument of sizeof() is the macro which expands to a number.

The analyzer has detected a potential error: a macro expanding into a number serves as an argument for the 'sizeof' operator. Using the operator in such a way can cause allocation of memory amount of incorrect size or other defects.

Consider an example:

#define NPOINT 100
char *point = (char *)malloc(sizeof(NPOINT)); 

Executing this code will result in allocation of insufficient memory amount. This is the correct code:

#define NPOINT 100
char *point = (char *)malloc(NPOINT);

According to Common Weakness Enumeration, potential errors found by using this diagnostic are classified as CWE-682.

You can look at examples of errors detected by the V627 diagnostic.

Bugs Found

Checked Projects
Collected Errors
12 668