From e7fc897a82758b158921c63df7b07d2535be8600 Mon Sep 17 00:00:00 2001 From: Kevin McCarthy Date: Fri, 19 Apr 2019 15:04:43 -0700 Subject: [PATCH] Convert pager help string to use struct Buffer Remove the awkward string truncation warnings, and remove helpstr and tmphelp char arrays from the stack. Because the pager is fairly long lived, allocate the helpstr instead of using the pool. Co-authored-by: Richard Russon --- pager.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/pager.c b/pager.c index 8622f43f1..b23d28112 100644 --- a/pager.c +++ b/pager.c @@ -1912,7 +1912,7 @@ struct PagerRedrawData PagerFlags search_flag; bool search_back; const char *banner; - char *helpstr; + const char *helpstr; char *searchbuf; struct Line *line_info; FILE *fp; @@ -2234,8 +2234,7 @@ int mutt_pager(const char *banner, const char *fname, PagerFlags flags, struct P { static char searchbuf[256] = ""; char buf[1024]; - char helpstr[1280]; - char tmphelp[256]; + struct Buffer *helpstr = NULL; int ch = 0, rc = -1; bool first = true; int searchctx = 0; @@ -2256,7 +2255,6 @@ int mutt_pager(const char *banner, const char *fname, PagerFlags flags, struct P rd.extra = extra; rd.indexlen = C_PagerIndexLines; rd.indicator = rd.indexlen / 3; - rd.helpstr = helpstr; rd.searchbuf = searchbuf; rd.has_types = (IsEmail(extra) || (flags & MUTT_SHOWCOLOR)) ? MUTT_TYPES : 0; /* main message or rfc822 attachment */ @@ -2294,24 +2292,27 @@ int mutt_pager(const char *banner, const char *fname, PagerFlags flags, struct P (rd.line_info[i].syntax)[0].last = -1; } - mutt_compile_help(helpstr, sizeof(helpstr), MENU_PAGER, PagerHelp); + helpstr = mutt_buffer_new(); + mutt_compile_help(buf, sizeof(buf), MENU_PAGER, PagerHelp); + mutt_buffer_strcpy(helpstr, buf); if (IsEmail(extra)) { - mutt_str_strfcpy(tmphelp, helpstr, sizeof(tmphelp)); mutt_compile_help(buf, sizeof(buf), MENU_PAGER, #ifdef USE_NNTP (Context && (Context->mailbox->magic == MUTT_NNTP)) ? PagerNewsHelpExtra : #endif PagerHelpExtra); - snprintf(helpstr, sizeof(helpstr), "%s %s", tmphelp, buf); + mutt_buffer_addch(helpstr, ' '); + mutt_buffer_addstr(helpstr, buf); } if (!InHelp) { - mutt_str_strfcpy(tmphelp, helpstr, sizeof(tmphelp)); mutt_make_help(buf, sizeof(buf), _("Help"), MENU_PAGER, OP_HELP); - snprintf(helpstr, sizeof(helpstr), "%s %s", tmphelp, buf); + mutt_buffer_addch(helpstr, ' '); + mutt_buffer_addstr(helpstr, buf); } + rd.helpstr = mutt_b2s(helpstr); rd.index_status_window = mutt_mem_calloc(1, sizeof(struct MuttWindow)); rd.index_window = mutt_mem_calloc(1, sizeof(struct MuttWindow)); @@ -3575,6 +3576,7 @@ int mutt_pager(const char *banner, const char *fname, PagerFlags flags, struct P if (rd.index) mutt_menu_destroy(&rd.index); + mutt_buffer_free(&helpstr); FREE(&rd.index_status_window); FREE(&rd.index_window); FREE(&rd.pager_status_window); -- 2.40.0