From 8e0271d9f6a15f40951ccd0b9df6b92f6d07f19c Mon Sep 17 00:00:00 2001 From: Florent Rougon Date: Mon, 29 Apr 2019 13:37:10 +0200 Subject: [PATCH] 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(ident), since 'ident' is of type 'int'. Then we get to compare two unsigned ints, which is well defined. --- 3rdparty/joystick/jsWindows.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/3rdparty/joystick/jsWindows.cxx b/3rdparty/joystick/jsWindows.cxx index ba9d1a71c..5c00988cd 100644 --- a/3rdparty/joystick/jsWindows.cxx +++ b/3rdparty/joystick/jsWindows.cxx @@ -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(ident) < joyGetNumDevs()) { os->js_id = JOYSTICKID1 + ident; open(); }