mirror of
https://github.com/libretro/RetroArch
synced 2025-02-10 03:39:56 +00:00
Avoid potential overflows with overlay analogs.
This commit is contained in:
parent
a65db38baf
commit
9ab4b2213a
10
retroarch.c
10
retroarch.c
@ -636,7 +636,15 @@ static int16_t input_state(unsigned port, unsigned device, unsigned index, unsig
|
|||||||
{
|
{
|
||||||
unsigned base = (index == RETRO_DEVICE_INDEX_ANALOG_RIGHT) ? 2 : 0;
|
unsigned base = (index == RETRO_DEVICE_INDEX_ANALOG_RIGHT) ? 2 : 0;
|
||||||
base += (id == RETRO_DEVICE_ID_ANALOG_Y) ? 1 : 0;
|
base += (id == RETRO_DEVICE_ID_ANALOG_Y) ? 1 : 0;
|
||||||
res += driver.overlay_state.analog[base];
|
|
||||||
|
// Simply adding here could overflow the int16_t.
|
||||||
|
int sum = res + driver.overlay_state.analog[base];
|
||||||
|
if (sum > 0x7fff)
|
||||||
|
res = 0x7fff;
|
||||||
|
else if (sum < -0x7fff)
|
||||||
|
res = -0x7fff;
|
||||||
|
else
|
||||||
|
res = sum;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user