Question on Undefined Right Shifts

Jeffrey Walton noloader@gmail.com
Wed Feb 20 00:19:00 GMT 2013


Hi All,

I've been using John Regehr's Integer Overflow Checker (IOC) on a few
libraries. It is a Clang plug-in and can be found at
http://embed.cs.utah.edu/ioc/.

The checker has flagged two libraries I use for performing undefined
right shifts:

CLANG ARITHMETIC UNDEFINED at <./xxx, (595:22)> : Op: >>, Reason :
Unsigned Right Shift: Right operand is negative or is greater than or
equal to the width of the promoted left operand, BINARY OPERATION:
left (uint32): 2196358166 right (uint32): 32

The fix seems easy enough on the surface: simply validate the
parameters before performing the shift. However, that could introduce
a timing difference in the function.

How could one fix the issue without introducing timing differences?

Jeff



More information about the Gcc mailing list