fix-utf8-status-padding-bug Ensure that multibyte UTF8 characters are counted correctly when calculating and displaying the caption and hardstatus lines. Based on an earlier version by Kees Cook Signed-off-by: Dustin Kirkland === modified file 'src/display.c' Index: screen/display.c =================================================================== --- screen.orig/display.c 2012-03-20 22:15:02.000000000 +0100 +++ screen/display.c 2012-03-20 22:41:28.000000000 +0100 @@ -2155,7 +2155,7 @@ { int chars = strlen_onscreen((unsigned char *)(s + start), (unsigned char *)(s + max)); D_encoding = 0; - PutWinMsg(s, start, max); + PutWinMsg(s, start, max + ((max - start) - chars)); /* Multibyte count */ D_encoding = UTF8; D_x -= (max - chars); /* Yak! But this is necessary to count for the fact that not every byte represents a @@ -2249,11 +2249,15 @@ RefreshHStatus() { char *buf; - +#ifdef UTF8 + int extrabytes = strlen(hstatusstring) - strlen_onscreen(hstatusstring, NULL); +#else + int extrabytes = 0; +#endif evdeq(&D_hstatusev); if (D_status == STATUS_ON_HS) return; - buf = MakeWinMsgEv(hstatusstring, D_fore, '%', (D_HS && D_has_hstatus == HSTATUS_HS && D_WS > 0) ? D_WS : D_width - !D_CLP, &D_hstatusev, 0); + buf = MakeWinMsgEv(hstatusstring, D_fore, '%', (D_HS && D_has_hstatus == HSTATUS_HS && D_WS > 0) ? D_WS : D_width - !D_CLP + extrabytes, &D_hstatusev, 0); if (buf && *buf) { ShowHStatus(buf); @@ -2348,8 +2352,13 @@ { if (y == cv->c_ye + 1 && from >= cv->c_xs && from <= cv->c_xe) { +#ifdef UTF8 + int extrabytes = strlen(captionstring) - strlen_onscreen(captionstring, NULL); +#else + int extrabytes = 0; +#endif p = Layer2Window(cv->c_layer); - buf = MakeWinMsgEv(captionstring, p, '%', cv->c_xe - cv->c_xs + (cv->c_xe + 1 < D_width || D_CLP), &cv->c_captev, 0); + buf = MakeWinMsgEv(captionstring, p, '%', cv->c_xe - cv->c_xs + (cv->c_xe + 1 < D_width || D_CLP) + extrabytes, &cv->c_captev, 0); if (cv->c_captev.timeout.tv_sec) evenq(&cv->c_captev); xx = to > cv->c_xe ? cv->c_xe : to; @@ -2358,7 +2367,7 @@ SetRendition(&mchar_so); if (l > xx - cv->c_xs + 1) l = xx - cv->c_xs + 1; - l = PrePutWinMsg(buf, from - cv->c_xs, l); + l = PrePutWinMsg(buf, from - cv->c_xs, l + extrabytes); from = cv->c_xs + l; for (; from <= xx; from++) PUTCHARLP(' ');