]> git.ipfire.org Git - thirdparty/newt.git/blobdiff - newt.c
- fixed help line drawing in UTF-8 (#81718)
[thirdparty/newt.git] / newt.c
diff --git a/newt.c b/newt.c
index 3b6dae0940eaef987e8783616023ef01b641b93e..1fe3fc77f799a03817e92719566fb8e2c69ea67f 100644 (file)
--- a/newt.c
+++ b/newt.c
@@ -653,15 +653,23 @@ void newtRedrawHelpLine(void) {
 
     SLsmg_set_color(NEWT_COLORSET_HELPLINE);
 
-    buf = alloca(SLtt_Screen_Cols + 1);
-    memset(buf, ' ', SLtt_Screen_Cols);
-    buf[SLtt_Screen_Cols] = '\0';
-
     if (currentHelpline) {
-       int len = wstrlen(*currentHelpline, -1);
-       if (SLtt_Screen_Cols < len)
-           len = SLtt_Screen_Cols;
-       memcpy(buf, *currentHelpline, len);
+       /* buffer size needs to be wide enough to hold all the multibyte
+          currentHelpline + all the single byte ' ' to fill the line */
+       int wlen = wstrlen(*currentHelpline, -1);
+       int len;
+
+       if (wlen > SLtt_Screen_Cols)
+           wlen = SLtt_Screen_Cols;
+       len = strlen(*currentHelpline) + (SLtt_Screen_Cols - wlen);
+       buf = alloca(len + 1);
+       memset(buf, ' ', len);
+       memcpy(buf, *currentHelpline, strlen(*currentHelpline));
+       buf[len] = '\0';
+    } else {
+       buf = alloca(SLtt_Screen_Cols + 1);
+       memset(buf, ' ', SLtt_Screen_Cols);
+       buf[SLtt_Screen_Cols] = '\0';
     }
     SLsmg_gotorc(SLtt_Screen_Rows - 1, 0);
     SLsmg_write_string(buf);