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:
parent
9b019f6b72
commit
8e0271d9f6
1 changed files with 1 additions and 1 deletions
2
3rdparty/joystick/jsWindows.cxx
vendored
2
3rdparty/joystick/jsWindows.cxx
vendored
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue