From d6e3514c0d75dc26e51eece22cf065311680451f Mon Sep 17 00:00:00 2001 From: William Wilgus Date: Thu, 21 Nov 2024 10:43:44 -0500 Subject: [PATCH] [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 --- apps/gui/list.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) 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;