Versions Compared

Key

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

Platform dependencies may be introduced to improve performance on a particular platform. This can be a dangerous practice, particularly if these dependencies are not appropriately documented during development and addressed during porting. Platform dependencies that have no performance or other benefits should consequently be avoided because they may introduce errors during porting.

The C Standard [ISO/IEC 9899:2011] identifies four different kinds of nonportable behavior. Each section of Annex J of the C Standard enumerates distinct instances of behaviors of each kind.

...

An example of undefined behavior is passing a null char* pointer as an argument to the printf function corresponding to the %s format specification. Although some implementations (such as the GNU C Library) provide well-defined semantics for this case, others do not and cause , causing programs that rely on this behavior to fail abnormally.

...

Code Block
bgColor#FFCCCC
langc
unsigned int ui1, ui2, sum;

if (~ui1 < ui2) {
  /* handleHandle error condition */
}
sum = ui1 + ui2;

This code assumes that the implementation uses two's complement representation. This assumption is commonly true but is not guaranteed by the standard.

...

Code Block
bgColor#ccccff
langc
unsigned int ui1, ui2, sum;

if (UINT_MAX - ui1 < ui2) {
  /* handleHandle error condition */
}
sum = ui1 + ui2;

...

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

Related Guidelines

...

...

...

Unspecified Behaviour [BQF]

Bibliography

[Dowd 2006]Chapter 6, "C Language Issues" ("Arithmetic Boundary Conditions," pp. 211–223)
[Seacord

...

2013]Chapter 5, "

...

Integer Security"

 

...