V620. It's unusual that the expression of sizeof(T)*N kind is being summed with the pointer to T type.

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.


Bugs Found

Checked Projects
411
Collected Errors
14 123
This website uses cookies and other technology to provide you a more personalized experience. By continuing the view of our web-pages you accept the terms of using these files. If you don't want your personal data to be processed, please, leave this site. Learn More →
Accept