Use static joyname instead of malloc

This commit is contained in:
mazmazz 2018-12-03 12:35:12 -05:00
parent d8e70c32e0
commit 8851f39b84
2 changed files with 8 additions and 24 deletions

View file

@ -1453,11 +1453,11 @@ INT32 I_NumJoys(void)
return numjoy; return numjoy;
} }
static char joyname[255]; // MAX_PATH; joystick name is straight from the driver
const char *I_GetJoyName(INT32 joyindex) const char *I_GetJoyName(INT32 joyindex)
{ {
const char *tempname = NULL; const char *tempname = NULL;
size_t templen;
char *joyname = NULL;
joyindex--; //SDL's Joystick System starts at 0, not 1 joyindex--; //SDL's Joystick System starts at 0, not 1
if (SDL_WasInit(SDL_INIT_JOYSTICK) == 0) if (SDL_WasInit(SDL_INIT_JOYSTICK) == 0)
{ {
@ -1465,11 +1465,7 @@ const char *I_GetJoyName(INT32 joyindex)
{ {
tempname = SDL_JoystickNameForIndex(joyindex); tempname = SDL_JoystickNameForIndex(joyindex);
if (tempname) if (tempname)
{ strncpy(joyname, tempname, 255);
templen = strlen(tempname);
joyname = malloc(templen*sizeof(char));
strcpy(joyname, tempname);
}
} }
SDL_QuitSubSystem(SDL_INIT_JOYSTICK); SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
} }
@ -1477,11 +1473,7 @@ const char *I_GetJoyName(INT32 joyindex)
{ {
tempname = SDL_JoystickNameForIndex(joyindex); tempname = SDL_JoystickNameForIndex(joyindex);
if (tempname) if (tempname)
{ strncpy(joyname, tempname, 255);
templen = strlen(tempname);
joyname = malloc(templen*sizeof(char));
strcpy(joyname, tempname);
}
} }
return joyname; return joyname;
} }

View file

@ -1575,11 +1575,11 @@ INT32 I_NumJoys(void)
return numjoy; return numjoy;
} }
static char joyname[255]; // MAX_PATH; joystick name is straight from the driver
const char *I_GetJoyName(INT32 joyindex) const char *I_GetJoyName(INT32 joyindex)
{ {
const char *tempname = NULL; const char *tempname = NULL;
size_t templen;
char *joyname = NULL;
joyindex--; //SDL's Joystick System starts at 0, not 1 joyindex--; //SDL's Joystick System starts at 0, not 1
if (SDL_WasInit(SDL_INIT_JOYSTICK) == 0) if (SDL_WasInit(SDL_INIT_JOYSTICK) == 0)
{ {
@ -1587,11 +1587,7 @@ const char *I_GetJoyName(INT32 joyindex)
{ {
tempname = SDL_JoystickNameForIndex(joyindex); tempname = SDL_JoystickNameForIndex(joyindex);
if (tempname) if (tempname)
{ strncpy(joyname, tempname, 255);
templen = strlen(tempname);
joyname = malloc(templen*sizeof(char));
strcpy(joyname, tempname);
}
} }
SDL_QuitSubSystem(SDL_INIT_JOYSTICK); SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
} }
@ -1599,11 +1595,7 @@ const char *I_GetJoyName(INT32 joyindex)
{ {
tempname = SDL_JoystickNameForIndex(joyindex); tempname = SDL_JoystickNameForIndex(joyindex);
if (tempname) if (tempname)
{ strncpy(joyname, tempname, 255);
templen = strlen(tempname);
joyname = malloc(templen*sizeof(char));
strcpy(joyname, tempname);
}
} }
return joyname; return joyname;
} }