Re: [hatari-devel] Crash when opening Mac preferences dialog

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


Hi Chris,

On 26.8.2023 17.33, Chris Jenkins wrote:
I built and ran Hatari on my Mac. Hatari crashes every time I try to open
the preferences dialog.

It looks like a problem was introduced in
commit 957d7db465970d1e34fde4c17e067c2009b32b57. Since that commit, the
function Midi_Host_GetPortName now falls back to a prefix match on the
supplied port name. Unfortunately, the Mac GUI code supplies a NULL pointer
here, which causes  Midi_Host_GetPortName to blow up when it calls strlen
on that NULL pointer.

Mac GUI code is still correct, my midi.c commit was broken.


Attached is a patch that causes the Mac GUI to match the behaviour of the
SDL GUI by populating the name parameter from config. This appears to fix
the crash (the preferences dialog can open without crashing Hatari now) but
I don't know how to test whether PortMidi actually works.

Thanks for the patch, and bisecting the issue!

However, SDL GUI gives the returned string back to Midi_Host_GetPortName() when using non-zero offsets.

And your patch breaks that i.e. Mac GUI would have just the name of the first MIDI device in the list, not all of them.


How does the patch look? And do you have any further suggestions for
testing this on my Mac?

Please try whether the attached patch fixes the crash.


	- Eero
From e0868746d8d11931472af6f2d6e5a6cc79699ddb Mon Sep 17 00:00:00 2001
From: Eero Tamminen <oak@xxxxxxxxxxxxxx>
Date: Sun, 27 Aug 2023 15:38:06 +0300
Subject: [PATCH] Fix Midi_Host_GetPortName() crash

Fix crash when called with NULL, and return first port name also
when called with empty string (using positive name offset).

Fixes: 957d7db465970d1e
---
 src/midi.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/src/midi.c b/src/midi.c
index 3261e8be..bf4f3607 100644
--- a/src/midi.c
+++ b/src/midi.c
@@ -429,8 +429,9 @@ static void Midi_Host_Close(void)
  *  <0: return name of device before matching one
  *  >0: return name of device after matching one
  *
- * As special case, for NULL name with positive offset,
- * name of the first port in correct direction is returned.
+ * As special case, for NULL/empty name with positive offset
+ * (i.e. before any port has been selected for the first time),
+ * name of the first port in that direction is returned.
  */
 const char* Midi_Host_GetPortName(const char *name, int offset, bool forInput)
 {
@@ -438,7 +439,9 @@ const char* Midi_Host_GetPortName(const char *name, int offset, bool forInput)
 	const char *prev = NULL;
 	const char *prefixmatch = NULL;
 	bool prev_matched = false;
-	int i, count, len = strlen(name);
+	int i, count, len;
+
+	len = name ? strlen(name) : 0;
 
 	// -- find port with given offset from named one
 	count = Pm_CountDevices();
@@ -451,7 +454,7 @@ const char* Midi_Host_GetPortName(const char *name, int offset, bool forInput)
 			continue;
 		if (!forInput && info->input)
 			continue;
-		if (!name)
+		if (len == 0)
 		{
 			if (offset <= 0)
 				return NULL;
-- 
2.39.2



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