From 8e758507b1876a04a8844701d6d7d3dae08f8aaf Mon Sep 17 00:00:00 2001 From: Arjun Balgovind <32061677+arjunbalgovind@users.noreply.github.com> Date: Wed, 24 Jun 2020 14:55:02 -0700 Subject: [PATCH] Enable code analysis on Keyboard Manager projects (#4455) * Enable code analysis and fix GetTickCount warning * Fix arithmetic casting warning --- src/modules/keyboardmanager/common/KeyDelay.cpp | 8 ++++---- src/modules/keyboardmanager/common/KeyDelay.h | 10 +++++----- .../common/KeyboardManagerCommon.vcxproj | 2 ++ .../common/KeyboardManagerConstants.h | 16 ++++++++-------- .../keyboardmanager/dll/KeyboardManager.vcxproj | 2 ++ .../test/KeyboardManagerTest.vcxproj | 2 ++ .../keyboardmanager/ui/KeyboardManagerUI.vcxproj | 2 ++ 7 files changed, 25 insertions(+), 17 deletions(-) diff --git a/src/modules/keyboardmanager/common/KeyDelay.cpp b/src/modules/keyboardmanager/common/KeyDelay.cpp index 0e41e7895f..0c7f384bda 100644 --- a/src/modules/keyboardmanager/common/KeyDelay.cpp +++ b/src/modules/keyboardmanager/common/KeyDelay.cpp @@ -24,7 +24,7 @@ KeyTimedEvent KeyDelay::NextEvent() return ev; } -bool KeyDelay::CheckIfMillisHaveElapsed(DWORD first, DWORD last, DWORD duration) +bool KeyDelay::CheckIfMillisHaveElapsed(DWORD64 first, DWORD64 last, DWORD64 duration) { if (first < last && first <= first + duration) { @@ -32,8 +32,8 @@ bool KeyDelay::CheckIfMillisHaveElapsed(DWORD first, DWORD last, DWORD duration) } else { - first += ULONG_MAX / 2; - last += ULONG_MAX / 2; + first += ULLONG_MAX / 2; + last += ULLONG_MAX / 2; return first + duration < last; } } @@ -99,7 +99,7 @@ bool KeyDelay::HandleOnHold(std::unique_lock& cvLock) } } - if (CheckIfMillisHaveElapsed(_initialHoldKeyDown, GetTickCount(), LONG_PRESS_DELAY_MILLIS)) + if (CheckIfMillisHaveElapsed(_initialHoldKeyDown, GetTickCount64(), LONG_PRESS_DELAY_MILLIS)) { if (_onLongPressDetected != nullptr) { diff --git a/src/modules/keyboardmanager/common/KeyDelay.h b/src/modules/keyboardmanager/common/KeyDelay.h index 164219e478..fd68ac971e 100644 --- a/src/modules/keyboardmanager/common/KeyDelay.h +++ b/src/modules/keyboardmanager/common/KeyDelay.h @@ -16,7 +16,7 @@ enum class KeyDelayState // Virtual key + timestamp (in millis since Windows startup) struct KeyTimedEvent { - DWORD time; + DWORD64 time; WPARAM message; }; @@ -61,7 +61,7 @@ private: // Check if milliseconds passed since millisecond. // Also checks for overflow conditions. - bool CheckIfMillisHaveElapsed(DWORD first, DWORD last, DWORD duration); + bool CheckIfMillisHaveElapsed(DWORD64 first, DWORD64 last, DWORD64 duration); std::thread _delayThread; bool _quit; @@ -81,11 +81,11 @@ private: std::condition_variable _cv; // Keeps track of the time at which the initial KEY_DOWN event happened. - DWORD _initialHoldKeyDown; + DWORD64 _initialHoldKeyDown; // Virtual Key provided in the constructor. Passed to callback functions. DWORD _key; - static const DWORD LONG_PRESS_DELAY_MILLIS = 900; - static const DWORD ON_HOLD_WAIT_TIMEOUT_MILLIS = 50; + static const DWORD64 LONG_PRESS_DELAY_MILLIS = 900; + static const DWORD64 ON_HOLD_WAIT_TIMEOUT_MILLIS = 50; }; diff --git a/src/modules/keyboardmanager/common/KeyboardManagerCommon.vcxproj b/src/modules/keyboardmanager/common/KeyboardManagerCommon.vcxproj index f81b9996a1..a46e97cbf6 100644 --- a/src/modules/keyboardmanager/common/KeyboardManagerCommon.vcxproj +++ b/src/modules/keyboardmanager/common/KeyboardManagerCommon.vcxproj @@ -49,11 +49,13 @@ true $(SolutionDir)$(Platform)\$(Configuration)\modules\KeyboardManager\ $(Platform)\$(Configuration)\obj\$(ProjectName)\ + true false $(SolutionDir)$(Platform)\$(Configuration)\modules\KeyboardManager\ $(Platform)\$(Configuration)\obj\$(ProjectName)\ + true diff --git a/src/modules/keyboardmanager/common/KeyboardManagerConstants.h b/src/modules/keyboardmanager/common/KeyboardManagerConstants.h index e2b4f532ef..32990ff0c9 100644 --- a/src/modules/keyboardmanager/common/KeyboardManagerConstants.h +++ b/src/modules/keyboardmanager/common/KeyboardManagerConstants.h @@ -57,7 +57,7 @@ namespace KeyboardManagerConstants inline const long RemapTableArrowColIndex = 1; inline const long RemapTableNewColIndex = 2; inline const long RemapTableRemoveColIndex = 3; - inline const DWORD RemapTableDropDownWidth = 110; + inline const DWORD64 RemapTableDropDownWidth = 110; // Shortcut table constants inline const long ShortcutTableColCount = 4; @@ -66,17 +66,17 @@ namespace KeyboardManagerConstants inline const long ShortcutTableArrowColIndex = 1; inline const long ShortcutTableNewColIndex = 2; inline const long ShortcutTableRemoveColIndex = 3; - inline const DWORD ShortcutTableDropDownWidth = 110; - inline const DWORD ShortcutTableDropDownSpacing = 10; + inline const DWORD64 ShortcutTableDropDownWidth = 110; + inline const DWORD64 ShortcutTableDropDownSpacing = 10; // Drop down height used for both Edit Keyboard and Edit Shortcuts - inline const DWORD TableDropDownHeight = 200; - inline const DWORD TableArrowColWidth = 20; - inline const DWORD TableRemoveColWidth = 20; - inline const DWORD TableWarningColWidth = 20; + inline const DWORD64 TableDropDownHeight = 200; + inline const DWORD64 TableArrowColWidth = 20; + inline const DWORD64 TableRemoveColWidth = 20; + inline const DWORD64 TableWarningColWidth = 20; // Shared style constants for both Remap Table and Shortcut Table - inline const double HeaderButtonWidth = 100; + inline const DWORD64 HeaderButtonWidth = 100; // Flags used for distinguishing key events sent by Keyboard Manager inline const ULONG_PTR KEYBOARDMANAGER_SINGLEKEY_FLAG = 0x11; // Single key remaps diff --git a/src/modules/keyboardmanager/dll/KeyboardManager.vcxproj b/src/modules/keyboardmanager/dll/KeyboardManager.vcxproj index 8fb52d2524..42466fbb94 100644 --- a/src/modules/keyboardmanager/dll/KeyboardManager.vcxproj +++ b/src/modules/keyboardmanager/dll/KeyboardManager.vcxproj @@ -51,11 +51,13 @@ true $(SolutionDir)$(Platform)\$(Configuration)\modules\$(ProjectName)\ $(Platform)\$(Configuration)\obj\$(ProjectName)\ + true false $(SolutionDir)$(Platform)\$(Configuration)\modules\$(ProjectName)\ $(Platform)\$(Configuration)\obj\$(ProjectName)\ + true diff --git a/src/modules/keyboardmanager/test/KeyboardManagerTest.vcxproj b/src/modules/keyboardmanager/test/KeyboardManagerTest.vcxproj index da1423bce3..c0eef3b979 100644 --- a/src/modules/keyboardmanager/test/KeyboardManagerTest.vcxproj +++ b/src/modules/keyboardmanager/test/KeyboardManagerTest.vcxproj @@ -51,11 +51,13 @@ true $(SolutionDir)$(Platform)\$(Configuration)\modules\KeyboardManager\ $(Platform)\$(Configuration)\obj\$(ProjectName)\ + true false $(SolutionDir)$(Platform)\$(Configuration)\modules\KeyboardManager\ $(Platform)\$(Configuration)\obj\$(ProjectName)\ + true diff --git a/src/modules/keyboardmanager/ui/KeyboardManagerUI.vcxproj b/src/modules/keyboardmanager/ui/KeyboardManagerUI.vcxproj index ada9f65490..ac61f7f85a 100644 --- a/src/modules/keyboardmanager/ui/KeyboardManagerUI.vcxproj +++ b/src/modules/keyboardmanager/ui/KeyboardManagerUI.vcxproj @@ -52,11 +52,13 @@ true $(SolutionDir)$(Platform)\$(Configuration)\modules\KeyboardManager\ $(Platform)\$(Configuration)\obj\$(ProjectName)\ + true false $(SolutionDir)$(Platform)\$(Configuration)\modules\KeyboardManager\ $(Platform)\$(Configuration)\obj\$(ProjectName)\ + true