Versions Compared

Key

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

...

Code Block
bgColor#ccccff
int si1, si2, sresult;

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

...

Code Block
bgColor#ccccff
unsigned int ui1, ui2, uresult;
unsigned int mod1, mod2;  

/* modulo behavior is allowed on mod1 and mod2 by exception */
unsigned int mod1, mod2;  

if ( (ui2 >= sizeof(unsigned int)*CHAR_BIT) 
  || (ui1 > (UINT_MAX  >> ui2))) ) 
{
  /* handle error condition */
}
else {
  uresult = ui1 << ui2;
}

if (mod2 >= sizeof(unsigned int)*CHAR_BIT) {
  /* handle error condition */
}
else {
  uresult = mod1 << mod2; /* modulo behavior is allowed by exception */
  uresult = mod1 << mod2; 
}

Non-Compliant Code Example (Right Shift)

...