fontdemo: Fix null pointer dereference

Fix possible null pointer dereference at line 314
when 'submenu' is NULL at line 297.
Pointed out by cppcheck.

Change-Id: I054f63d574f4a9608df49d48ee74b87cd0116f69
Reviewed-on: https://review.haiku-os.org/c/haiku/+/3492
Reviewed-by: Jérôme Duval <jerome.duval@gmail.com>
This commit is contained in:
Murai Takashi 2020-12-10 19:05:11 +09:00 committed by Jérôme Duval
parent 5b627acb33
commit 6182c5ad27

View File

@ -294,10 +294,12 @@ ControlView::MessageReceived(BMessage* msg)
const_cast<char*>(currentFamilyItem->Label()));
BMenu* submenu = currentFamilyItem->Submenu();
if (submenu) {
BMenuItem* markedStyle = submenu->FindMarked();
fFontStyleindex = submenu->IndexOf(markedStyle);
if (submenu == NULL) {
printf("Failed to get style.\n");
return;
}
BMenuItem* markedStyle = submenu->FindMarked();
fFontStyleindex = submenu->IndexOf(markedStyle);
if (fFontStyleindex < installedStyles - 1)
fFontStyleindex++;