From d43d008cb8c535140e8ce560870c1f3b062fa625 Mon Sep 17 00:00:00 2001 From: Florian Stinglmayr Date: Wed, 17 Jul 2019 19:48:58 +0200 Subject: [PATCH] fix error in line printing --- ncdc/src/textview.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/ncdc/src/textview.c b/ncdc/src/textview.c index dcc8476..1383ad6 100644 --- a/ncdc/src/textview.c +++ b/ncdc/src/textview.c @@ -203,7 +203,7 @@ ncdc_textview_render_msgs(ncdc_textview_t v, WINDOW *win, int lines, int cols) for (i = msgs-1; i >= 0; i--) { dc_message_t m = dc_channel_nth_message(v->channel, i); wchar_t *s = ncdc_textview_format(m); - wchar_t const *end = s, *last = NULL; + wchar_t const *end = s, *last = s; size_t len = 0; size_t needed_lines = 0; @@ -211,16 +211,13 @@ ncdc_textview_render_msgs(ncdc_textview_t v, WINDOW *win, int lines, int cols) */ while ((end = wcschr(end, '\n')) != NULL) { ++needed_lines; + ++end; - len = wcswidth(last, (end - last)); - needed_lines += (len % cols); + len = wcswidth(last, (end - last - 1)); + needed_lines += (len / cols); last = end; } - if (last == NULL) { - last = s; - } - len = wcswidth(last, wcslen(last)); needed_lines += (len / cols) + 1;