streaminfo2.cpp fix possible segfault if audio mode mismatch

This commit is contained in:
Jacek Jendrzej
2014-12-30 13:29:11 +01:00
parent 47f2b31786
commit b8e8e46a98

View File

@@ -556,16 +556,19 @@ void CStreamInfo2::paint_techinfo(int xpos, int ypos)
g_Font[font_info]->RenderString (xpos, ypos, box_width, buf, COL_INFOBAR_TEXT); g_Font[font_info]->RenderString (xpos, ypos, box_width, buf, COL_INFOBAR_TEXT);
if(type == AUDIO_FMT_MPEG) { if(type == AUDIO_FMT_MPEG) {
const char *mpegmodes[4] = { "stereo", "joint_st", "dual_ch", "single_ch" }; const int max_mode = 4;
sprintf (buf, "MPEG %s (%d)", mpegmodes[mode], freq); const char *mpegmodes[max_mode] = { "stereo", "joint_st", "dual_ch", "single_ch" };
sprintf (buf, "MPEG %s (%d)", (mode > max_mode) ?"unk":mpegmodes[mode], freq);
} else if (type == AUDIO_FMT_DOLBY_DIGITAL || type == AUDIO_FMT_DD_PLUS) { } else if (type == AUDIO_FMT_DOLBY_DIGITAL || type == AUDIO_FMT_DD_PLUS) {
const char *ddmodes[8] = { "CH1/CH2", "C", "L/R", "L/C/R", "L/R/S", "L/C/R/S", "L/R/SL/SR", "L/C/R/SL/SR" }; const int max_mode = 8;
const char *ddmodes[max_mode] = { "CH1/CH2", "C", "L/R", "L/C/R", "L/R/S", "L/C/R/S", "L/R/SL/SR", "L/C/R/SL/SR" };
sprintf (buf, "%s %s (%d)", sprintf (buf, "%s %s (%d)",
(type == AUDIO_FMT_DOLBY_DIGITAL) ? "DD" : "DD+", (type == AUDIO_FMT_DOLBY_DIGITAL) ? "DD" : "DD+",
ddmodes[mode], (mode > max_mode) ?"unk": ddmodes[mode],
freq); freq);
} else if (type == AUDIO_FMT_AAC || type == AUDIO_FMT_AAC_PLUS) { } else if (type == AUDIO_FMT_AAC || type == AUDIO_FMT_AAC_PLUS) {
const char *aacmodes[10] = { const int max_mode = 10;
const char *aacmodes[max_mode] = {
"N/S", "N/S",
"Mono", "Mono",
"L/R", "L/R",
@@ -579,7 +582,7 @@ void CStreamInfo2::paint_techinfo(int xpos, int ypos)
}; };
sprintf (buf, "%s %s (%d)", sprintf (buf, "%s %s (%d)",
(type == AUDIO_FMT_AAC) ? "AAC" : "AAC+", (type == AUDIO_FMT_AAC) ? "AAC" : "AAC+",
aacmodes[mode], freq); (mode > max_mode) ?"unk":aacmodes[mode], freq);
} else { } else {
sprintf (buf, "%s (%d)", g_Locale->getText(LOCALE_STREAMINFO_AUDIOTYPE_UNKNOWN), freq); sprintf (buf, "%s (%d)", g_Locale->getText(LOCALE_STREAMINFO_AUDIOTYPE_UNKNOWN), freq);
} }