Out-of-bounds array access means accessing an element outside the range belonging to its array. C often leaves verification to the programmer, so such access can contribute to crashes, data loss, incorrect results, sensitive-information exposure, or financial and physical harm. section 15.0
Make array expectations visible
C function declarations can express different expectations about an array argument: `void func(double a[static 1]);` indicates a non-null pointer to at least one element, while `void func(double a[static 7]);` expresses an expectation of at least seven elements. A size-dependent form is `void func(size_t n, double a[n]);`; the pointer form `void func(double *a);` communicates less about array requirements. section 15.0
TAKEAWAY
- Do not trade off safety for performance. section 15.0
- Treat array-bound verification as a programming responsibility when the language does not enforce it. section 15.0
void func(double a[static 1]); !@%STYLE%@! {"css":"{\"css\": \"font-weight: bold;\"}","target":"[[{\"line\":0,\"ch\":0},{\"line\":0,\"ch\":4}],[{\"line\":0,\"ch\":10},{\"line\":0,\"ch\":16}],[{\"line\":0,\"ch\":19},{\"line\":0,\"ch\":25}]]"} !@%STYLE%@!
Inspect the declaration that marks a single required array element with `static 1`. section 15.0
