[Bf-blender-cvs] [065a1cd0b1b] master: Cleanup: check GetKeyboardState succeeds before using it's values

Campbell Barton noreply at git.blender.org
Wed Aug 31 07:05:21 CEST 2022


Commit: 065a1cd0b1b12aa371d52de5e5c7b0f634533ff8
Author: Campbell Barton
Date:   Wed Aug 31 14:26:54 2022 +1000
Branches: master
https://developer.blender.org/rB065a1cd0b1b12aa371d52de5e5c7b0f634533ff8

Cleanup: check GetKeyboardState succeeds before using it's values

Quiets compiler warning.

===================================================================

M	intern/ghost/intern/GHOST_SystemWin32.cpp

===================================================================

diff --git a/intern/ghost/intern/GHOST_SystemWin32.cpp b/intern/ghost/intern/GHOST_SystemWin32.cpp
index 8b196ca3118..c03d468160a 100644
--- a/intern/ghost/intern/GHOST_SystemWin32.cpp
+++ b/intern/ghost/intern/GHOST_SystemWin32.cpp
@@ -1156,10 +1156,10 @@ GHOST_EventKey *GHOST_SystemWin32::processKeyEvent(GHOST_WindowWin32 *window, RA
    * those events here as well. */
   if (!is_repeated_modifier) {
     char utf8_char[6] = {0};
-    BYTE state[256] = {0};
-    GetKeyboardState((PBYTE)state);
-    bool ctrl_pressed = state[VK_CONTROL] & 0x80;
-    bool alt_pressed = state[VK_MENU] & 0x80;
+    BYTE state[256];
+    const BOOL has_state = GetKeyboardState((PBYTE)state);
+    const bool ctrl_pressed = has_state && state[VK_CONTROL] & 0x80;
+    const bool alt_pressed = has_state && state[VK_MENU] & 0x80;
 
     if (!key_down) {
       /* Pass. */



More information about the Bf-blender-cvs mailing list