Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
bgColor#FFCCCC
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).

...