Skip to content

Commit

Permalink
Fix crash on startup when there are no MIDI devices and autoconnect i…
Browse files Browse the repository at this point in the history
…s enabled
  • Loading branch information
pedrolcl committed Dec 8, 2024
1 parent e604d9e commit 9f8508e
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions src/drivers/fluid_winmidi.c
Original file line number Diff line number Diff line change
Expand Up @@ -484,24 +484,26 @@ static void fluid_winmidi_autoconnect_build_name(char *name)
int j;
unsigned int i, n = 0;
unsigned int num = midiInGetNumDevs();

for (i = 0; i < num; ++i)
if (num > 0)
{
char x[4];
j = FLUID_SNPRINTF(x, sizeof(x), "%d;", i);
n += j;
if (n >= sizeof(new_name))
for (i = 0; i < num; ++i)
{
FLUID_LOG(FLUID_DBG, "winmidi: autoconnect dev name exceeds MAXPNAMELEN (%d), num (%d), n (%d)", MAXPNAMELEN, num, n);
return;
char x[4];
j = FLUID_SNPRINTF(x, sizeof(x), "%d;", i);
n += j;
if (n >= sizeof(new_name))
{
FLUID_LOG(FLUID_DBG, "winmidi: autoconnect dev name exceeds MAXPNAMELEN (%d), num (%d), n (%d)", MAXPNAMELEN, num, n);
return;
}
strncat(new_name, x, j);
}
strncat(new_name, x, j);

name[n - 1] = 0;

FLUID_MEMSET(name, 0, MAXPNAMELEN);
FLUID_STRCPY(name, new_name);
}

name[n - 1] = 0;

FLUID_MEMSET(name, 0, MAXPNAMELEN);
FLUID_STRCPY(name, new_name);
}

/*
Expand Down

0 comments on commit 9f8508e

Please sign in to comment.