ui/ncurses: Check for NULL in pmenu_item_get_index()
authorSamuel Mendoza-Jonas <sam.mj@au1.ibm.com>
Wed, 11 Nov 2015 05:11:41 +0000 (16:11 +1100)
committerSamuel Mendoza-Jonas <sam.mj@au1.ibm.com>
Thu, 17 Dec 2015 03:51:46 +0000 (14:51 +1100)
Fixes Coverity defect #30476

Signed-off-by: Samuel Mendoza-Jonas <sam.mj@au1.ibm.com>
ui/ncurses/nc-menu.c

index 3f09d62385b4df4043e985d965347aad13c905c1..dda7626410974ec778089f8a24b9ed6f6857bc2d 100644 (file)
@@ -322,9 +322,10 @@ static int pmenu_item_get_index(const struct pmenu_item *item)
 {
        unsigned int i;
 
-       for (i = 0; i < item->pmenu->item_count; i++)
-               if (item->pmenu->items[i] == item->nci)
-                       return i;
+       if (item)
+               for (i = 0; i < item->pmenu->item_count; i++)
+                       if (item->pmenu->items[i] == item->nci)
+                               return i;
 
        pb_log("%s: not found: %p %s\n", __func__, item,
                (item ? item->nci->name.str : "(null)"));