Fixed race condition and potential b/o in char input

git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@2528 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
avolkov
2006-11-24 14:50:52 +00:00
parent 2d32359778
commit 9e0dea0293
+17 -7
View File
@@ -35,7 +35,8 @@
static int kbdhead=0, kbdtail=0;
static wchar_t kbdbuf[KBDBUFSIZE];
static wchar_t lastchar;
static int kbdstate[SDLK_LAST];
static int kbdstate[SDLK_LAST + 1];
// +1 for tracking all yet unknown keys
static BOOLEAN InputInitialized = FALSE;
@@ -315,24 +316,33 @@ ProcessInputEvent (const SDL_Event *Event)
ProcessMouseEvent (Event);
VControl_HandleEvent (Event);
if (Event->type == SDL_KEYDOWN || Event->type == SDL_KEYUP)
{ // process character input event, if any
SDLKey k = Event->key.keysym.sym;
wchar_t map_key = Event->key.keysym.unicode;
if (k < 0 || k > SDLK_LAST)
k = SDLK_LAST; // for unknown keys
if (Event->type == SDL_KEYDOWN)
{
int newtail;
// dont care about the non-printable, non-char
if (!map_key)
return;
kbdstate[k]++;
ImmediateInputState.menu[KEY_MENU_ANY]++;
lastchar = map_key;
kbdbuf[kbdtail] = map_key;
kbdtail = (kbdtail + 1) & (KBDBUFSIZE - 1);
if (kbdtail == kbdhead)
kbdhead = (kbdhead + 1) & (KBDBUFSIZE - 1);
newtail = (kbdtail + 1) & (KBDBUFSIZE - 1);
// ignore the char if the buffer is full
if (newtail != kbdhead)
{
kbdbuf[kbdtail] = map_key;
kbdtail = newtail;
lastchar = map_key;
ImmediateInputState.menu[KEY_MENU_ANY]++;
}
}
else if (Event->type == SDL_KEYUP)
{