[Fix] Avoid some other possible seg faults.

This commit is contained in:
Allanis 2014-05-28 21:37:26 +01:00
parent 71f4ce95d2
commit 5ae72bcacd
4 changed files with 15 additions and 3 deletions

View File

@ -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. */

View File

@ -1,5 +1,6 @@
#pragma once
#include <ctype.h>
#include <SDL/SDL.h>
/**
* @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)

View File

@ -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) : "",

View File

@ -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))