Fix Bug 1533 - SDL_Keycode value range allows segfaults with negative values; add test coverage to keyboard suite

This commit is contained in:
Andreas Schiffler 2013-03-08 23:04:53 -08:00
parent f41de44a36
commit 5916b2bc1e
2 changed files with 133 additions and 57 deletions

View file

@ -861,7 +861,7 @@ SDL_GetKeyFromScancode(SDL_Scancode scancode)
{
SDL_Keyboard *keyboard = &SDL_keyboard;
if (scancode<SDL_SCANCODE_UNKNOWN || scancode >= SDL_NUM_SCANCODES) {
if (scancode < SDL_SCANCODE_UNKNOWN || scancode >= SDL_NUM_SCANCODES) {
SDL_InvalidParamError("scancode");
return 0;
}
@ -887,8 +887,13 @@ SDL_GetScancodeFromKey(SDL_Keycode key)
const char *
SDL_GetScancodeName(SDL_Scancode scancode)
{
const char *name = SDL_scancode_names[scancode];
const char *name;
if (scancode < SDL_SCANCODE_UNKNOWN || scancode >= SDL_NUM_SCANCODES) {
SDL_InvalidParamError("scancode");
return "";
}
name = SDL_scancode_names[scancode];
if (name)
return name;
else