aboutsummaryrefslogtreecommitdiff
path: root/engines/wintermute/base
diff options
context:
space:
mode:
authorlolbot-iichan2018-08-17 00:19:20 +0300
committerTobia Tesan2018-08-23 11:33:13 +0200
commite97b1e560d4f3a0eed758047e8c40ecc69c98231 (patch)
tree2a681a821b83793aa6c5ca815a28adb61c808749 /engines/wintermute/base
parent52b4206771c89e8424204921626da34029cbf801 (diff)
downloadscummvm-rg350-e97b1e560d4f3a0eed758047e8c40ecc69c98231.tar.gz
scummvm-rg350-e97b1e560d4f3a0eed758047e8c40ecc69c98231.tar.bz2
scummvm-rg350-e97b1e560d4f3a0eed758047e8c40ecc69c98231.zip
WINTERMUTE: Check keyboard state array index
vKeyToKeyCode() method was unsafe if vkey >= KEYSTATES_ARRAY_SIZE was provided, fixed
Diffstat (limited to 'engines/wintermute/base')
-rw-r--r--engines/wintermute/base/base_keyboard_state.cpp8
1 files changed, 5 insertions, 3 deletions
diff --git a/engines/wintermute/base/base_keyboard_state.cpp b/engines/wintermute/base/base_keyboard_state.cpp
index 44da804b75..e35e544918 100644
--- a/engines/wintermute/base/base_keyboard_state.cpp
+++ b/engines/wintermute/base/base_keyboard_state.cpp
@@ -32,6 +32,8 @@
#include "common/system.h"
#include "common/keyboard.h"
+#define KEYSTATES_ARRAY_SIZE (Common::KEYCODE_UNDO + 1) // Hardcoded size for the common/keyboard.h enum
+
namespace Wintermute {
IMPLEMENT_PERSISTENT(BaseKeyboardState, false)
@@ -46,8 +48,8 @@ BaseKeyboardState::BaseKeyboardState(BaseGame *inGame) : BaseScriptable(inGame)
_currentAlt = false;
_currentControl = false;
- _keyStates = new uint8[323]; // Hardcoded size for the common/keyboard.h enum
- for (int i = 0; i < 323; i++) {
+ _keyStates = new uint8[KEYSTATES_ARRAY_SIZE];
+ for (int i = 0; i < KEYSTATES_ARRAY_SIZE; i++) {
_keyStates[i] = false;
}
}
@@ -499,7 +501,7 @@ Common::KeyCode BaseKeyboardState::vKeyToKeyCode(uint32 vkey) {
return Common::KEYCODE_SCROLLOCK;
default:
warning("Unknown VKEY: %d", vkey);
- return (Common::KeyCode)vkey;
+ return (Common::KeyCode)(vkey < KEYSTATES_ARRAY_SIZE ? vkey : 0);
break;
}