diff options
author | William Wilgus <wilgus.william@gmail.com> | 2021-07-21 18:30:48 -0400 |
---|---|---|
committer | William Wilgus <me.theuser@yahoo.com> | 2021-08-03 11:00:59 +0000 |
commit | 1fd190d02dfbb10f5e02a98bd20b698e14e0a5bc (patch) | |
tree | 71a4280973cf644018a2fe1377a32246d664d876 /apps | |
parent | 36e48a8bb262a0e85f5c43f54d12ef617708c0a5 (diff) | |
download | rockbox-1fd190d02dfbb10f5e02a98bd20b698e14e0a5bc.tar.gz rockbox-1fd190d02dfbb10f5e02a98bd20b698e14e0a5bc.zip |
mask_select guard against null pointers
Change-Id: I83d246c13d22c1e76a55cbfdd20dcc955eb556ec
Diffstat (limited to 'apps')
-rw-r--r-- | apps/gui/mask_select.c | 62 |
1 files changed, 35 insertions, 27 deletions
diff --git a/apps/gui/mask_select.c b/apps/gui/mask_select.c index e22ba7dd03..c39b3583ac 100644 --- a/apps/gui/mask_select.c +++ b/apps/gui/mask_select.c | |||
@@ -79,11 +79,14 @@ static int calculate_mask_r(struct category *root, int mask) | |||
79 | while (i < root->children_count) | 79 | while (i < root->children_count) |
80 | { | 80 | { |
81 | struct child *this = &root->children[i]; | 81 | struct child *this = &root->children[i]; |
82 | if (this->state == SELECTED) | 82 | if (this) |
83 | mask |= this->key_value; | 83 | { |
84 | if (this->state == SELECTED) | ||
85 | mask |= this->key_value; | ||
84 | 86 | ||
85 | else if (this->state == EXPANDED) | 87 | else if (this->state == EXPANDED) |
86 | mask = calculate_mask_r(this->category, mask); | 88 | mask = calculate_mask_r(this->category, mask); |
89 | } | ||
87 | i++; | 90 | i++; |
88 | } | 91 | } |
89 | return mask; | 92 | return mask; |
@@ -97,7 +100,7 @@ static int count_items(struct category *start) | |||
97 | for (i=0; i<start->children_count; i++) | 100 | for (i=0; i<start->children_count; i++) |
98 | { | 101 | { |
99 | struct child *foo = &start->children[i]; | 102 | struct child *foo = &start->children[i]; |
100 | if (foo->state == EXPANDED) | 103 | if (foo && foo->state == EXPANDED) |
101 | count += count_items(foo->category); | 104 | count += count_items(foo->category); |
102 | count++; | 105 | count++; |
103 | } | 106 | } |
@@ -120,7 +123,7 @@ static struct child* find_index(struct category *start, | |||
120 | return foo; | 123 | return foo; |
121 | } | 124 | } |
122 | i++; | 125 | i++; |
123 | if (foo->state == EXPANDED) | 126 | if (foo && foo->state == EXPANDED) |
124 | { | 127 | { |
125 | struct child *bar = find_index(foo->category, index - i, parent); | 128 | struct child *bar = find_index(foo->category, index - i, parent); |
126 | if (bar) | 129 | if (bar) |
@@ -141,7 +144,7 @@ static int item_action_callback(int action, struct gui_synclist *list) | |||
141 | struct category *parent; | 144 | struct category *parent; |
142 | struct child *this = find_index(root, list->selected_item, &parent); | 145 | struct child *this = find_index(root, list->selected_item, &parent); |
143 | 146 | ||
144 | if (action == ACTION_STD_OK) | 147 | if (action == ACTION_STD_OK && this) |
145 | { | 148 | { |
146 | switch (this->state) | 149 | switch (this->state) |
147 | { | 150 | { |
@@ -194,16 +197,18 @@ static const char * item_get_name(int selected_item, void * data, | |||
194 | for(int i = 0; i <= parent->depth; i++) | 197 | for(int i = 0; i <= parent->depth; i++) |
195 | strcat(buffer, "\t\0"); | 198 | strcat(buffer, "\t\0"); |
196 | 199 | ||
197 | /* state of selection needs icons so if icons are disabled use text*/ | 200 | if (this) |
198 | if (!global_settings.show_icons) | 201 | { |
199 | { | 202 | /* state of selection needs icons so if icons are disabled use text*/ |
200 | if (this->state == SELECTED) | 203 | if (!global_settings.show_icons) |
201 | strcat(buffer, "+\0"); | 204 | { |
202 | else | 205 | if (this->state == SELECTED) |
203 | strcat(buffer," \0"); | 206 | strcat(buffer, "+\0"); |
204 | } | 207 | else |
205 | strlcat(buffer, P2STR((const unsigned char *)this->name), buffer_len); | 208 | strcat(buffer," \0"); |
206 | 209 | } | |
210 | strlcat(buffer, P2STR((const unsigned char *)this->name), buffer_len); | ||
211 | } | ||
207 | return buffer; | 212 | return buffer; |
208 | } | 213 | } |
209 | 214 | ||
@@ -212,7 +217,7 @@ static int item_get_talk(int selected_item, void *data) | |||
212 | struct category *root = (struct category*)data; | 217 | struct category *root = (struct category*)data; |
213 | struct category *parent; | 218 | struct category *parent; |
214 | struct child *this = find_index(root, selected_item , &parent); | 219 | struct child *this = find_index(root, selected_item , &parent); |
215 | if (global_settings.talk_menu) | 220 | if (global_settings.talk_menu && this) |
216 | { | 221 | { |
217 | long id = P2ID((const unsigned char *)(this->name)); | 222 | long id = P2ID((const unsigned char *)(this->name)); |
218 | if(id>=0) | 223 | if(id>=0) |
@@ -234,16 +239,19 @@ static enum themable_icons item_get_icon(int selected_item, void * data) | |||
234 | struct category *parent; | 239 | struct category *parent; |
235 | struct child *this = find_index(root, selected_item, &parent); | 240 | struct child *this = find_index(root, selected_item, &parent); |
236 | 241 | ||
237 | switch (this->state) | 242 | if (this) |
238 | { | 243 | { |
239 | case SELECTED: | 244 | switch (this->state) |
240 | return Icon_Submenu; | 245 | { |
241 | case COLLAPSED: | 246 | case SELECTED: |
242 | return Icon_NOICON; | 247 | return Icon_Submenu; |
243 | case EXPANDED: | 248 | case COLLAPSED: |
244 | return Icon_Submenu_Entered; | 249 | return Icon_NOICON; |
245 | default: | 250 | case EXPANDED: |
246 | return Icon_NOICON; | 251 | return Icon_Submenu_Entered; |
252 | default: | ||
253 | return Icon_NOICON; | ||
254 | } | ||
247 | } | 255 | } |
248 | return Icon_NOICON; | 256 | return Icon_NOICON; |
249 | } | 257 | } |