You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Rule 6.5.7 of ISO/IEC 9899:1999 (E) standard describes Bitwise shift operators.
Paragraph 5 states:
The result of E1 >> E2 is E1 right-shifted E2 bit positions. If E1 has an unsigned type
or if E1 has a signed type and a nonnegative value, the value of the result is the integral
part of the quotient of E1 divided by the quantity, 2 raised to the power E2. If E1 has a
signed type and a negative value, the resulting value is implementation-defined.
So, right shifing a negative number is implementation-defined (undefined behavior), if it is really negative, basically because it depends on how the sign bit is implemented.
But nobody can know if during the execution E1 will be negative or positive.
This is one of the reasons why shifting a signed integer (that can be negative, during the program execution) is not a good idea.
Shinfting unsigned integeres only stays on the safe side for every scenario.
Here are some points in the source code where signed integers are shifted:
Rule 6.5.7 of ISO/IEC 9899:1999 (E) standard describes Bitwise shift operators.
Paragraph 5 states:
So, right shifing a negative number is implementation-defined (undefined behavior), if it is really negative, basically because it depends on how the sign bit is implemented.
But nobody can know if during the execution E1 will be negative or positive.
This is one of the reasons why shifting a signed integer (that can be negative, during the program execution) is not a good idea.
Shinfting unsigned integeres only stays on the safe side for every scenario.
Here are some points in the source code where signed integers are shifted:
CMSIS-DSP/Include/dsp/none.h
Line 139 in 93c4e4a
CMSIS-DSP/Include/dsp/none.h
Line 149 in 93c4e4a
CMSIS-DSP/Include/dsp/none.h
Line 160 in 93c4e4a
CMSIS-DSP/Include/dsp/none.h
Line 170 in 93c4e4a
Is it possible having them fixed so that tools for static analysis do not complain about them?
Thanks
The text was updated successfully, but these errors were encountered: