Versions Compared

Key

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

...

When it is executed, if expression (which must have a scalar type) is false, the assert macro writes information about the particular call that failed (including the text of the argument, the name of the source file, the source line number, and the name of the enclosing function) on the standard error stream in an implementation-defined format and calls the abort() function.

In the following example, the test for integer wrap has been omitted for the on unsigned multiplication based on the assumption that MAX_TABLE_SIZE * sizeof(char *) cannot exceed SIZE_MAX. While we know this is true, it cannot do any harm to codify this assumption.

Code Block
bgColor#ccccff

  assert(size <= SIZE_MAX/sizeof(char *));
  table_size = size * sizeof(char *);

Risk Assessment

Assertions are a valuable diagnostic tool for finding and eliminating software defects that may result in vulnerabilities. The absence of assertions, however, does not mean that code is incorrect.

...