The analyzer has detected that a variable of the pointer type is added to an expression containing the sizeof(T) operator. Using the operator in such a way might indicate incorrect address arithmetic.
Consider a simplest example:
int *p;
size_t N = 5;
...
p = p + sizeof(int)*N;
This use is incorrect. It is expected that we will move by N items in the data structure. Instead, a 20-item shift occurs, as sizeof(int) value is 4 in 32-bit programs. As a result, we'll get the following: "p = p + 20;". Perhaps there is a misprint or other mistake. This is the correct code:
int *p;
size_t N = 5;
...
p = p + N;
Note. The analyzer considers the code correct if the char type is being handled in it. Consider a sample where the analyzer won't generate the warning:
char *c;
size_t N = 5;
...
c = c + sizeof(float)*N;
This diagnostic is classified as:
|
You can look at examples of errors detected by the V620 diagnostic. |