SDL-1.2: os2joystick: miscellaneous clean-ups.

From 30639a07838448bc913a5d77cc28d7653f407662 Mon Sep 17 00:00:00 2001
From: Ozkan Sezer <[EMAIL REDACTED]>
Date: Sat, 1 Jan 2022 20:50:10 +0300
Subject: [PATCH] os2joystick: miscellaneous clean-ups.

---
 src/joystick/os2/SDL_sysjoystick.c | 21 ++++++++-------------
 1 file changed, 8 insertions(+), 13 deletions(-)

diff --git a/src/joystick/os2/SDL_sysjoystick.c b/src/joystick/os2/SDL_sysjoystick.c
index 31901e276..c10c673ca 100644
--- a/src/joystick/os2/SDL_sysjoystick.c
+++ b/src/joystick/os2/SDL_sysjoystick.c
@@ -152,7 +152,7 @@ struct _joycfg
 /* OS/2 Implementation Function Prototypes */
 static int joyPortOpen(HFILE * hGame);
 static void joyPortClose(HFILE * hGame);
-static int joyGetData(char *joyenv, char *name, char stopchar, size_t maxchars);
+static int joyGetData(const char *joyenv, char *name, char stopchar, size_t maxchars);
 static int joyGetEnv(struct _joycfg * joydata);
 
 
@@ -394,14 +394,12 @@ int SDL_SYS_JoystickOpen(SDL_Joystick *joystick)
 	int i;			/* Generic Counter */
 
 	/* allocate memory for system specific hardware data */
-	joystick->hwdata = (struct joystick_hwdata *) SDL_malloc(sizeof(*joystick->hwdata));
-	if (joystick->hwdata == NULL)
+	joystick->hwdata = (struct joystick_hwdata *) SDL_calloc(1, sizeof(*joystick->hwdata));
+	if (!joystick->hwdata)
 	{
 		SDL_OutOfMemory();
 		return -1;
 	}
-	/* Reset Hardware Data */
-	SDL_memset(joystick->hwdata, 0, sizeof(*joystick->hwdata));
 
 	/* ShortCut Pointer */
 	index = joystick->index;
@@ -514,7 +512,7 @@ void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick)
 	if (SYS_JoyData[index].id == 1) corr = 2;
 	else corr = 0;
 	normbut = 4;	/* Number of normal buttons */
-	if (joystick->nbuttons<normbut) normbut = joystick->nbuttons;
+	if (joystick->nbuttons < normbut) normbut = joystick->nbuttons;
 	for (i = corr; (i-corr) < normbut; ++i)
 	{
 		/*
@@ -578,11 +576,8 @@ void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick)
 /******************************************/
 void SDL_SYS_JoystickClose(SDL_Joystick *joystick)
 {
-	if (joystick->hwdata != NULL)
-	{
-		/* free system specific hardware data */
-		SDL_free(joystick->hwdata);
-	}
+	/* free system specific hardware data */
+	SDL_free(joystick->hwdata);
 }
 
 /********************************************************************/
@@ -654,7 +649,7 @@ static void joyPortClose(HFILE * hGame)
 /***************************/
 static int joyGetEnv(struct _joycfg * joydata)
 {
-	char *joyenv;				/* Pointer to tested character */
+	const char *joyenv;		/* Pointer to tested character */
 	char tempnumber[5];		/* Temporary place to put numeric texts */
 
 	joyenv = SDL_getenv("SDL_OS2_JOYSTICK");
@@ -696,7 +691,7 @@ static int joyGetEnv(struct _joycfg * joydata)
 /* Get a text from in the string starting in joyenv until it finds		*/
 /* the stopchar or maxchars is reached. The result is placed in name.	*/
 /************************************************************************/
-static int joyGetData(char *joyenv, char *name, char stopchar, size_t maxchars)
+static int joyGetData(const char *joyenv, char *name, char stopchar, size_t maxchars)
 {
 	char *nameptr;			/* Pointer to the selected character */
 	int chcnt = 0;			/* Count how many characters where copied */