Right-shifting by 32 is too far for 32-bit int type (undefined behavior)
kcgen opened this issue · comments
Flagged by gcc version 10.2.0 (Ubuntu 10.2.0-13ubuntu1) when libmt32emu is instrumented with Undefined Behavior Sanitizer detection:
MT32: LCD-Message: INSERT BUCKAZOID
MT32: LCD-Message: * SPACE QUEST III *
munt-libmt32emu_2_4_2/mt32emu/src/TVP.cpp:343:57: runtime error: shift exponent 32 is too large for 32-bit type 'int'
Confirmed. The original hardware also hits unspecified behaviour in such cases. As can be found in 80C196 spec, permitted range for any shift operation is 0-31 but the value of the counter may happily exceed the limit. However, I'm not 100% sure whether we emulate such behaviour correctly atm (I'm only able to refer to the commit 4198070 where we deal with a similar thing).