From: <av...@us...> - 2011-08-08 15:56:29
|
Revision: 3666 http://sc2.svn.sourceforge.net/sc2/?rev=3666&view=rev Author: avolkov Date: 2011-08-08 15:56:23 +0000 (Mon, 08 Aug 2011) Log Message: ----------- Compiling with no joystick warning fixes (bug #50); SDLKey signedness warning fixes and hardening Modified Paths: -------------- trunk/sc2/src/libs/input/sdl/input.c Modified: trunk/sc2/src/libs/input/sdl/input.c =================================================================== --- trunk/sc2/src/libs/input/sdl/input.c 2011-08-03 20:27:14 UTC (rev 3665) +++ trunk/sc2/src/libs/input/sdl/input.c 2011-08-08 15:56:23 UTC (rev 3666) @@ -33,7 +33,7 @@ static int kbdhead=0, kbdtail=0; static UniChar kbdbuf[KBDBUFSIZE]; static UniChar lastchar; -static unsigned int num_keys = 0; +static int num_keys = 0; static int *kbdstate = NULL; // Holds all SDL keys +1 for holding invalid values @@ -213,20 +213,13 @@ num_flight = num_flight_; } -int -TFB_InitInput (int driver, int flags) +#ifdef HAVE_JOYSTICK + +static void +initJoystick (void) { - int i; int nJoysticks; - (void)driver; - (void)flags; - SDL_EnableUNICODE(1); - (void)SDL_GetKeyState (&num_keys); - kbdstate = (int *)HMalloc (sizeof (int) * (num_keys + 1)); - - -#ifdef HAVE_JOYSTICK if ((SDL_InitSubSystem(SDL_INIT_JOYSTICK)) == -1) { log_add (log_Fatal, "Couldn't initialize joystick subsystem: %s", @@ -239,6 +232,8 @@ nJoysticks = SDL_NumJoysticks (); if (nJoysticks > 0) { + int i; + log_add (log_Info, "The names of the joysticks are:"); for (i = 0; i < nJoysticks; i++) { @@ -246,8 +241,25 @@ } SDL_JoystickEventState (SDL_ENABLE); } +} + #endif /* HAVE_JOYSTICK */ +int +TFB_InitInput (int driver, int flags) +{ + (void)driver; + (void)flags; + + SDL_EnableUNICODE(1); + (void)SDL_GetKeyState (&num_keys); + kbdstate = (int *)HMalloc (sizeof (int) * (num_keys + 1)); + + +#ifdef HAVE_JOYSTICK + initJoystick (); +#endif /* HAVE_JOYSTICK */ + in_character_mode = FALSE; resetKeyboardState (); @@ -350,10 +362,12 @@ if (Event->type == SDL_KEYDOWN || Event->type == SDL_KEYUP) { // process character input event, if any - SDLKey k = Event->key.keysym.sym; + // keysym.sym is an SDLKey type which is an enum and can be signed + // or unsigned on different platforms; we'll use a guaranteed type + int k = Event->key.keysym.sym; UniChar map_key = Event->key.keysym.unicode; - if (k > num_keys) + if (k < 0 || k > num_keys) k = num_keys; // for unknown keys if (Event->type == SDL_KEYDOWN) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |