munt / munt

A multi-platform software synthesiser emulating pre-GM MIDI devices such as the Roland MT-32, CM-32L, CM-64 and LAPC-I. In no way endorsed by or affiliated with Roland Corp.

Home Page:http://munt.sourceforge.net/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Right-shifting by 32 is too far for 32-bit int type (undefined behavior)

kcgen opened this issue · comments

commented

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).