...
Code Block | ||
---|---|---|
| ||
void incr(int *intptr) { if (intptr == NULL) { /* Handle error */ } *intptr++; } |
Compliant Solution (validation)
This incr()
function can be improved by using the valid()
function. The resulting implementation is less likely to dereference an invalid pointer or write to memory that is outside the bounds of a valid object.
...
The valid()
function can be implementation dependent and perform additional, platform dependent checks when possible.
Compliant Solution (
...
assertion
)
Because invalid pointers are often indicative of a defect in the program, the assert()
macro can be used to terminate immediately if an invalid pointer is discovered (see MSC11-C. Incorporate diagnostic tests using assertions).
...