mask_select guard against null pointers

Change-Id: I83d246c13d22c1e76a55cbfdd20dcc955eb556ec
This commit is contained in:
William Wilgus 2021-07-21 18:30:48 -04:00 committed by William Wilgus
parent 36e48a8bb2
commit 1fd190d02d

View file

@ -79,11 +79,14 @@ static int calculate_mask_r(struct category *root, int mask)
while (i < root->children_count) while (i < root->children_count)
{ {
struct child *this = &root->children[i]; struct child *this = &root->children[i];
if (this->state == SELECTED) if (this)
mask |= this->key_value; {
if (this->state == SELECTED)
mask |= this->key_value;
else if (this->state == EXPANDED) else if (this->state == EXPANDED)
mask = calculate_mask_r(this->category, mask); mask = calculate_mask_r(this->category, mask);
}
i++; i++;
} }
return mask; return mask;
@ -97,7 +100,7 @@ static int count_items(struct category *start)
for (i=0; i<start->children_count; i++) for (i=0; i<start->children_count; i++)
{ {
struct child *foo = &start->children[i]; struct child *foo = &start->children[i];
if (foo->state == EXPANDED) if (foo && foo->state == EXPANDED)
count += count_items(foo->category); count += count_items(foo->category);
count++; count++;
} }
@ -120,7 +123,7 @@ static struct child* find_index(struct category *start,
return foo; return foo;
} }
i++; i++;
if (foo->state == EXPANDED) if (foo && foo->state == EXPANDED)
{ {
struct child *bar = find_index(foo->category, index - i, parent); struct child *bar = find_index(foo->category, index - i, parent);
if (bar) if (bar)
@ -141,7 +144,7 @@ static int item_action_callback(int action, struct gui_synclist *list)
struct category *parent; struct category *parent;
struct child *this = find_index(root, list->selected_item, &parent); struct child *this = find_index(root, list->selected_item, &parent);
if (action == ACTION_STD_OK) if (action == ACTION_STD_OK && this)
{ {
switch (this->state) switch (this->state)
{ {
@ -194,16 +197,18 @@ static const char * item_get_name(int selected_item, void * data,
for(int i = 0; i <= parent->depth; i++) for(int i = 0; i <= parent->depth; i++)
strcat(buffer, "\t\0"); strcat(buffer, "\t\0");
/* state of selection needs icons so if icons are disabled use text*/ if (this)
if (!global_settings.show_icons) {
{ /* state of selection needs icons so if icons are disabled use text*/
if (this->state == SELECTED) if (!global_settings.show_icons)
strcat(buffer, "+\0"); {
else if (this->state == SELECTED)
strcat(buffer," \0"); strcat(buffer, "+\0");
} else
strlcat(buffer, P2STR((const unsigned char *)this->name), buffer_len); strcat(buffer," \0");
}
strlcat(buffer, P2STR((const unsigned char *)this->name), buffer_len);
}
return buffer; return buffer;
} }
@ -212,7 +217,7 @@ static int item_get_talk(int selected_item, void *data)
struct category *root = (struct category*)data; struct category *root = (struct category*)data;
struct category *parent; struct category *parent;
struct child *this = find_index(root, selected_item , &parent); struct child *this = find_index(root, selected_item , &parent);
if (global_settings.talk_menu) if (global_settings.talk_menu && this)
{ {
long id = P2ID((const unsigned char *)(this->name)); long id = P2ID((const unsigned char *)(this->name));
if(id>=0) if(id>=0)
@ -234,16 +239,19 @@ static enum themable_icons item_get_icon(int selected_item, void * data)
struct category *parent; struct category *parent;
struct child *this = find_index(root, selected_item, &parent); struct child *this = find_index(root, selected_item, &parent);
switch (this->state) if (this)
{ {
case SELECTED: switch (this->state)
return Icon_Submenu; {
case COLLAPSED: case SELECTED:
return Icon_NOICON; return Icon_Submenu;
case EXPANDED: case COLLAPSED:
return Icon_Submenu_Entered; return Icon_NOICON;
default: case EXPANDED:
return Icon_NOICON; return Icon_Submenu_Entered;
default:
return Icon_NOICON;
}
} }
return Icon_NOICON; return Icon_NOICON;
} }