sb_create_from_settings: Fix crash when ui viewport setting malformed

The 'Purple_Glow_V3' theme uses the following
'UI viewport' setting which is missing a comma
after the viewport height:

ui viewport: 0,0,271,212-,-,-

The setting is actually ignored when loading this theme,
since a UI viewport is already defined in the supplied
SBS file.

Rockbox will crash, though, when and if the next theme
that is loaded resets the SBS by setting it to "-", but
doesn't adjust the UI viewport setting at the same time.

To fix, use default UI viewport when encountering fewer
parameters than expected for the UI viewport setting.

Change-Id: I2648565ac59369ce8ab18d8e84b7fa69ad767f25
This commit is contained in:
Christian Soffke 2025-03-24 23:40:56 +01:00
parent 325d71a579
commit 2b30a9fed8

View file

@ -252,22 +252,28 @@ char* sb_create_from_settings(enum screen_type screen)
comma = strchr(comma+1, ','); comma = strchr(comma+1, ',');
} while (comma && param_count < 6); } while (comma && param_count < 6);
if (comma) if (comma && strchr(comma+1, ','))
{ {
char *end = comma; char *end = comma;
char fg[8], bg[8]; char fg[8], bg[8];
int i = 0; int i = 0;
comma++; comma++;
while (*comma != ',') while (*comma != ',' && i < (int) sizeof(fg) - 1)
fg[i++] = *comma++; fg[i++] = *comma++;
fg[i] = '\0'; comma++; i=0; fg[i] = '\0'; comma++; i=0;
while (*comma != ')') while (*comma != ')' && i < (int) sizeof(bg) - 1)
bg[i++] = *comma++; bg[i++] = *comma++;
bg[i] = '\0'; bg[i] = '\0';
len += snprintf(end, remaining-len, ") %%Vf(%s) %%Vb(%s)\n", fg, bg); len += snprintf(end, remaining-len, ") %%Vf(%s) %%Vb(%s)\n", fg, bg);
} }
else
{
ptr2[0] = '-';
ptr2[1] = '\0';
}
} }
else
if (!ptr2[0] || ptr2[0] == '-')
{ {
int y = 0, height; int y = 0, height;
switch (bar_position) switch (bar_position)