Versions Compared

Key

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

...

...

...

...

...

...

Noncompliant Code Example (assert)

...

Code Block
bgColor#FFcccc
langc
#include <assert.h>
#include "myassert.h"
 
void fullAssert(int e) {
  assert(e > 0); //* Invoke standard library assert() */
  (assert)(e > 0); /*
                    //* assert() macro suppressed,; calling
                    * function assert().
                    */
}

Having this function and attempting to access it produces undefined behavior.  It is also a violation of DCL37-C. Do not declare or define a reserved identifier.

...

Code Block
bgColor#ccccff
langc
#include <assert.h>
#include "myassert.h"
 
void fullAssert(int e) {
  assert(e > 0); //* Standard library assert() */
  myassert(e > 0); //* Well-defined custom assertion function */
}

Noncompliant Code Example (Redefining errno)

...

Code Block
bgColor#ccccff
langc
#include <errno.h>

C-conforming implementations are implementations are required to declare errno in <errno.h>, although some historic implementations failed to do so.

...

Accessing objects or functions underlying these macros does not produce defined behavior, which may lead to incorrect or unexpected program behavior.

Rule

Severity

Likelihood

Remediation Cost

Priority

Level

MSC38-C

lowLow

unlikelyUnlikely

mediumMedium

P2

L3

Related Vulnerabilities

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

Related Guidelines

Bibliography

[ISO/IEC 9899:2011]Annex J, subclause J.2, "Undefined behavior"

 

...