summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilliam Wilgus <wilgus.william@gmail.com>2024-11-21 10:43:44 -0500
committerWilliam Wilgus <me.theuser@yahoo.com>2024-11-21 10:46:27 -0500
commitd6e3514c0d75dc26e51eece22cf065311680451f (patch)
tree116e44dc932ee42399362a11190adb1fd3ef8169
parent35a913473eea2f85fc6cf186a488540c4d0b8627 (diff)
downloadrockbox-d6e3514c0d.tar.gz
rockbox-d6e3514c0d.zip
[BugFix] gui/list.c simplelist_set_line_count > 1 list buffer corruption
when line was > 0 static item might not be in buffer after 35a913473e Change-Id: I6fefb16d05d132f8f0e4bbbbfcf471342a434072
-rw-r--r--apps/gui/list.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/apps/gui/list.c b/apps/gui/list.c
index c20d981911..3853b0049b 100644
--- a/apps/gui/list.c
+++ b/apps/gui/list.c
@@ -813,7 +813,24 @@ void simplelist_set_line_count(int lines)
simplelist_line_count = 0;
}
else if (lines < simplelist_line_count) {
- const char *end = simplelist_text[lines];
+ const char *end = simplelist_buffer;
+ int last_line = 0;
+ const char * const bufend = simplelist_buffer + sizeof(simplelist_buffer);
+ /* find the last item in the buffer we are still showing */
+ for (int line = 0; line <= lines; line++)
+ {
+ const char *first = simplelist_text[line];
+ if (first >= simplelist_buffer && first < bufend)
+ {
+ last_line = line;
+ end = first;
+ }
+ line++;
+ }
+
+ if (last_line < lines)
+ end += strlen(end) + 1; /* prior to the current line, save contents */
+
simplelist_line_pos = end - simplelist_buffer;
simplelist_line_remaining = sizeof(simplelist_buffer) - simplelist_line_pos;
simplelist_line_count = lines;