Re: [hatari-devel] Joystick dialog crashes with Ubuntu 24.04

[ Thread Index | Date Index | More lists.tuxfamily.org/hatari-devel Archives ]


Am Fri, 5 Jul 2024 17:00:06 +0300
schrieb Eero Tamminen <oak@xxxxxxxxxxxxxx>:

> Hi,
> 
> User is reporting that opening SDL GUI Joystick dialog crashes Hatari, 
> on Lubuntu 24.04:
> 	https://www.atari-forum.com/viewtopic.php?p=466100
> 
> Is anybody here using some Ubuntu 24.04 variant?   And if yes, can you 
> reproduce the issue?
> 
> 
> I took a quick look at the related code, and it's possible that SDL 
> Joystick name query may get given invalid struct address if SDL reports 
> error or no joysticks, or user has invalid joystick mapping in his 
> config file.
> 
> Attached patch will hopefully handle such issues.  Any comments on it?


 
 /**
- * Return maximum available real joystick ID
+ * Return maximum available real joystick ID, or
+ * zero on error or no joystick (to avoid invalid array accesses)
  */
 int Joy_GetMaxId(void)
 {
 	int count = SDL_NumJoysticks();
 	if (count > JOYSTICK_COUNT)
 		count = JOYSTICK_COUNT;
-	return count - 1;
+	if (count > 0)
+		return count - 1;
+	return 0;
 }

That looks fishy ... how do you distinguish now between no joystick and one
joystick? Both will return 0 now here.

 Thomas



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/