Versions Compared

Key

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

...

By using the invalid() function defined above, the function is less likely to modify memory outside its bounds (see MSC11-A. Incorporate diagnostic tests using assertions).

Code Block
bgColor#ccccff
void incr(int *intptr) {
  if (invalid( intptr)) {
    /* handle error */
  }
  *intptr++;
}

...

Since invalid pointers are often indicative of a bug in the program, one can use the assert() macro to terminate immediately if an invalid pointer is discovered (see MSC11-A. Incorporate diagnostic tests using assertions).

Code Block
bgColor#ccccff
#include <assert.h>

void incr(int *intptr) {
  assert(!invalid( intptr));
  *intptr++;
}

...