The C Standard, Section subclause 7.2.1.1 [ISO/IEC 9899:2011], defines assert()
to have the following behavior:
...
Code Block | ||||
---|---|---|---|---|
| ||||
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 | ||||
---|---|---|---|---|
| ||||
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 |
---|---|---|---|
|
| Can detect some violations of this rule. However, it can only detect violations involving |
Related Vulnerabilities
Search for vulnerabilities resulting from the violation of this rule on the CERT website.
Related Guidelines
CERT C++ Secure Coding Standard | ERR06-CPP. Understand the termination behavior of assert() and abort() |
ISO/IEC TR 24772:2013 | Termination Strategy [REU] |
Bibliography
[ISO/IEC 9899:2011] | Section Subclause 7.2.1.1, "The assert Macro" |
...