From 559de8eedbc5cc18982bb254527ed7fe2f8655b2 Mon Sep 17 00:00:00 2001 From: "Alfonso S. Siciliano" Date: Mon, 6 Jun 2022 21:07:03 +0200 Subject: [PATCH] bsddialog(3): Fix text wrapping Fix text wrapping with more than 1024 words. Reported by: brd Reviewed by: bapt, brd Differential Revision: https://reviews.freebsd.org/D35413 --- contrib/bsddialog/lib/lib_util.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/contrib/bsddialog/lib/lib_util.c b/contrib/bsddialog/lib/lib_util.c index 643830efd58..506003b52c8 100644 --- a/contrib/bsddialog/lib/lib_util.c +++ b/contrib/bsddialog/lib/lib_util.c @@ -443,9 +443,10 @@ text_autosize(struct bsddialog_conf *conf, const char *text, int maxrows, continue; } - if (nword + tablen >= maxwords) { + if (nword + tablen + 1 >= maxwords) { maxwords += 1024; - if (realloc(words, maxwords * sizeof(int)) == NULL) + words = realloc(words, maxwords * sizeof(int)); + if (words == NULL) RETURN_ERROR("Cannot realloc memory for text " "autosize"); } @@ -968,4 +969,4 @@ end_dialog(struct bsddialog_conf *conf, WINDOW *shadow, WINDOW *widget, *conf->get_height = h; if (conf->get_width != NULL) *conf->get_width = w; -} \ No newline at end of file +}