SWORD25: Fix out of bounds writes when pressing keys like ctrl or F-keys

This fixes a crash one got by quitting via the GMM.

svn-id: r53876
This commit is contained in:
Max Horn 2010-10-27 15:15:59 +00:00
parent 9ab69ab6f4
commit b5e41b3a82
2 changed files with 4 additions and 1 deletions

View File

@ -169,6 +169,7 @@ void InputEngine::testForLeftDoubleClick() {
}
void InputEngine::alterKeyboardState(int keycode, byte newState) {
assert(keycode < ARRAYSIZE(_keyboardState[_currentState]));
_keyboardState[_currentState][keycode] = newState;
}
@ -193,10 +194,12 @@ int InputEngine::getMouseY() {
}
bool InputEngine::isKeyDown(uint keyCode) {
assert(keyCode < ARRAYSIZE(_keyboardState[_currentState]));
return (_keyboardState[_currentState][keyCode] & 0x80) != 0;
}
bool InputEngine::wasKeyDown(uint keyCode) {
assert(keyCode < ARRAYSIZE(_keyboardState[_currentState]));
return ((_keyboardState[_currentState][keyCode] & 0x80) == 0) &&
((_keyboardState[_currentState ^ 1][keyCode] & 0x80) != 0);
}

View File

@ -309,7 +309,7 @@ private:
void testForLeftDoubleClick();
void alterKeyboardState(int keycode, byte newState);
byte _keyboardState[2][256];
byte _keyboardState[2][512];
bool _leftMouseState[2];
bool _rightMouseState[2];
uint _currentState;