Versions Compared

Key

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

...

This compliant solution tests the suspect shift operation to guarantee there is no possibility of unsigned overflow.

Code Block
bgColor#ccccff
unsigned int si1, si2, result;

if ( (si2 < 0) || (si2 < 0) || (si2 >= sizeof(int)*CHAR_BIT) || (si1 > (INT_MAX / (1 << si2)) ) {
  /* handle error condition */
}
result = si1 << si2;

...