From 3a78406d56e2d3ce31a8e2807908eac797a579c5 Mon Sep 17 00:00:00 2001 From: Chris Allegretta Date: Mon, 10 Feb 2003 02:32:58 +0000 Subject: [PATCH] - nano.c:help_init() - Fix crashing in do_help when COLS < 23 (David Benbennick) git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1441 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- ChangeLog | 2 ++ nano.c | 13 ++++++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 528db07f..6312858d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -13,6 +13,8 @@ CVS code main() - Fix nano not compiling with ENABLE_RCFILE and DISABLE_TABCOMP (David Benbennick). + help_init() + - Fix crashing in do_help when COLS < 23 (David Benbennick). - rcfile.c: colortoint() - Don't bomb after invalid color and print bad color name diff --git a/nano.c b/nano.c index e80ee1d5..07217646 100644 --- a/nano.c +++ b/nano.c @@ -389,9 +389,12 @@ void help_init(void) /* If we're on the main list, we also count the toggle help text. * Each line has "M-%c\t\t\t", which fills 24 columns, plus at most * COLS - 24 characters, plus '\n'.*/ - if (currshortcut == main_list) + if (currshortcut == main_list) { + size_t endislen = strlen(_("enable/disable")); + for (t = toggles; t != NULL; t = t->next) - allocsize += COLS - 17; + allocsize += 8 + strlen(t->desc) + endislen; + } #endif /* !NANO_SMALL */ /* help_text has been freed and set to NULL unless the user resized @@ -448,16 +451,16 @@ void help_init(void) *(ptr++) = '\t'; assert(s->help != NULL); - ptr += sprintf(ptr, "%.*s\n", COLS - 24, s->help); + ptr += sprintf(ptr, "%.*s\n", COLS > 24 ? COLS - 24 : 0, s->help); } #ifndef NANO_SMALL /* And the toggles... */ if (currshortcut == main_list) for (t = toggles; t != NULL; t = t->next) { - ptr += sprintf(ptr, "M-%c\t\t\t", t->val - 32); assert(t->desc != NULL); - ptr += sprintf(ptr, _("%.*s enable/disable\n"), COLS - 24, t->desc); + ptr += sprintf(ptr, "M-%c\t\t\t%s %s\n", t->val - 32, t->desc, + _("enable/disable")); } #endif /* !NANO_SMALL */