C library functions that make changes to arrays or objects take at least two arguments: a pointer to the array or object and an integer indicating the number of elements or bytes to be manipulated. If improper arguments are supplied to such a function, it might cause the function to form a pointer that does not point into or just past the end of the object, resulting in undefined behavior.
The C Standard identifies the following distinct situations in which undefined behavior (UB) can arise as a result of invalid pointer operations:
UB | Description |
---|---|
The pointer passed to a library function array parameter does not have a value such that all address computations and object accesses are valid. |
For the purposes of this rule, the element count of a pointer is the size of the object to which it points, expressed by the number of elements that are valid to access.
...