From 5ae72bcacd34831f3274580235ae8058bf145c2b Mon Sep 17 00:00:00 2001 From: Allanis Date: Wed, 28 May 2014 21:37:26 +0100 Subject: [PATCH] [Fix] Avoid some other possible seg faults. --- src/input.c | 1 + src/lstd.h | 11 +++++++++++ src/options.c | 4 ++-- src/toolkit.c | 2 +- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/input.c b/src/input.c index 3a585ae..05112c9 100644 --- a/src/input.c +++ b/src/input.c @@ -14,6 +14,7 @@ #include "map.h" #include "escort.h" #include "land.h" +#include "lstd.h" #include "input.h" #define KEY_PRESS ( 1.) /**< Key is pressed. */ diff --git a/src/lstd.h b/src/lstd.h index 035cc58..e14be23 100644 --- a/src/lstd.h +++ b/src/lstd.h @@ -1,5 +1,6 @@ #pragma once #include +#include /** * @brief Check to see if k is in ascii area. @@ -26,3 +27,13 @@ */ #define lstd_isspace(k) (lstd_checkascii(k) ? isspace(k) : 0) +/** + * @brief Convert a key to lowercase if applicable. + */ +#define lstd_tolower(k) (lstd_checkascii(k) ? (SDLKey)tolower(k) : k) + +/** + * @brief Convert a key to uppercase if applicable. + */ +#define lstd_toupper(k) (lstd_checkascii(k) ? (SDLKey)toupper(k) : k) + diff --git a/src/options.c b/src/options.c index c61cc7f..0a4777c 100644 --- a/src/options.c +++ b/src/options.c @@ -68,7 +68,7 @@ void opt_menuKeybinds(void) { case KEYBIND_KEYBOARD: /* SDL_GetKeyName returns lowercase which is ugly. */ if(lstd_isalpha(key)) - snprintf(str[j], 64, "%s <%c>", keybindNames[j], toupper(key)); + snprintf(str[j], 64, "%s <%c>", keybindNames[j], lstd_toupper(key)); else snprintf(str[j], 64, "%s <%s>", keybindNames[j], SDL_GetKeyName(key)); break; @@ -152,7 +152,7 @@ static void menuKeybinds_update(unsigned int wid, char* name) { snprintf(bind, 32, "keyboard: %s%s%c", (mod != KMOD_NONE) ? modToText(mod) : "", (mod != KMOD_NONE) ? " + " : "", - toupper(key)); + lstd_toupper(key)); else snprintf(bind, 32, "keyboard: %s%s%s", (mod != KMOD_NONE) ? modToText(mod) : "", diff --git a/src/toolkit.c b/src/toolkit.c index 9ae00a1..13439ef 100644 --- a/src/toolkit.c +++ b/src/toolkit.c @@ -1994,7 +1994,7 @@ static int toolkit_inputInput(Uint8 type, Widget* inp, SDLKey key) { /* Uppder case characters. */ else if(lstd_isalpha(key) && (mods & (KMOD_LSHIFT | KMOD_RSHIFT))) - inp->dat.inp.input[inp->dat.inp.pos++] = toupper(key); + inp->dat.inp.input[inp->dat.inp.pos++] = lstd_toupper(key); /* Rest. */ else if(!lstd_iscntrl(key))