Synopsis: | Do not misuse a pointer when an array is requested |
Language: | C++ |
Severity Level: | 2 |
Category: | Class Interface |
Description: |
When a pointer is used as reference to an array, it shall refer to an array of the correct type. Example: void Foo( int a[], int size ) { // do something with a; for (int i = 0; i < size; i++) { a[i] = i; } } int ar[] = {0,0,0}; Foo( ar, sizeof(ar)/sizeof(ar[0]) ); // Ok ... int* ptr = &ar[1]; Foo( ptr, sizeof(ar)/sizeof(ar[0]) ); //Not allowed: passing pointer ptr in Foo causes out of array bounds. |