...
This compliant solution tests the suspect shift operation to guarantee there is no possibility of unsigned overflow.
Code Block | ||
---|---|---|
| ||
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; |
...