1
0
Fork 0

jsWindows: remove undefined behavior when joyGetNumDevs() > INT_MAX

If joyGetNumDevs() > INT_MAX, casting it to an 'int' leads to undefined
behavior. On the other hand, after the 'ident >= 0' test succeeded, it
is perfectly safe to use static_cast<unsigned int>(ident), since 'ident'
is of type 'int'. Then we get to compare two unsigned ints, which is
well defined.
This commit is contained in:
Florent Rougon 2019-04-29 13:37:10 +02:00
parent 9b019f6b72
commit 8e0271d9f6

View file

@ -179,7 +179,7 @@ jsJoystick::jsJoystick ( int ident )
id = ident ;
os = new struct os_specific_s;
if (ident >= 0 && ident < (int)joyGetNumDevs()) {
if (ident >= 0 && static_cast<unsigned int>(ident) < joyGetNumDevs()) {
os->js_id = JOYSTICKID1 + ident;
open();
}