Versions Compared

Key

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

The C Standard, Section subclause 7.2.1.1 [ISO/IEC 9899:2011], defines assert() to have the following behavior:

...

Code Block
bgColor#ffcccc
langc
void cleanup(void) {
  /* Delete temporary files, restore consistent state, etc. */
}

int main(void) {
  if (atexit(cleanup) != 0) {
    /* Handle error */
  }

  /* ... */

  assert(/* somethingSomething bad didn't happen */);

  /* ... */
}

...

Code Block
bgColor#ccccff
langc
void cleanup(void) {
  /* Delete temporary files, restore consistent state, etc. */
}

int main(void) {
  if (atexit(cleanup) != 0) {
    /* Handle error */
  }

  /* ... */

  if (/* somethingSomething bad happened */) {
    exit(EXIT_FAILURE);
  }

  /* ... */
}

...

Recommendation

Severity

Likelihood

Remediation Cost

Priority

Level

ERR06-C

mediumMedium

unlikelyUnlikely

mediumMedium

P4

L3

Automated Detection

Tool

Version

Checker

Description

Compass/ROSE

 

 

Can detect some violations of this rule. However, it can only detect violations involving abort() because assert() is implemented as a macro

Related Vulnerabilities

Search for vulnerabilities resulting from the violation of this rule on the CERT website.

Related Guidelines

Bibliography

[ISO/IEC 9899:2011]Section Subclause 7.2.1.1, "The assert Macro"

...