Versions Compared

Key

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

...

Noncompliant Code Example

This noncompliant code noncompliant code example demonstrates how performing bitwise operations on integer types smaller than int may have unexpected results:

...

Noncompliant Code Example

This noncompliant example noncompliant code example, taken from the Cryptography Services blog, demonstrates how signed overflow can occur even when it seems that only unsigned types are in use:

...

On implementations where short is 16 bits wide and int is 32 bits wide, the program results in undefined behavior due to signed overflow, . This is because the unsigned shorts become signed when they 're are automatically promoted to integer. Finally, their mathematical product 2250000000 is greater than 2147483647 (aka 231 - 1) which is the largest signed 32-bit integer.

Compliant Solution

...