...
In this non-compliant example a the insert() function is used to add values to a buffer in a modulo fashion, that is inserting values into the beginning of the buffer once the end is reached. However, the variable used to index the array, index, is not guaranteed to be positive. If index is negative then the result of (index+1)%size will also be negative. This causes a If the programmer does not realize this, the new value to will be inserted in to a negative offset within list.
| Code Block | ||
|---|---|---|
| ||
int insert(int index, int *list, int size, int value) {
index = ( index + 1) % size;
list[index] = value;
return index;
}
|
| Wiki Markup |
|---|
This example does not comply with \[[INT01-A. Use size_t for all integer values representing the size of an object]\]. |
Implementation Details
Microsoft Visual Studio
...