summaryrefslogtreecommitdiff
path: root/debian/patches/51fix-utf8-status-padding-bug.patch
blob: a5c3da71e3219db95a1aad40106d7ddbf95bf12c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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 <address@hidden>

Signed-off-by: Dustin Kirkland <address@hidden>

=== modified file 'src/display.c'
Index: screen/display.c
===================================================================
--- screen.orig/display.c	2014-04-17 14:23:17.247036061 +0200
+++ screen/display.c	2014-04-17 14:23:17.235036151 +0200
@@ -2163,7 +2163,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
@@ -2257,11 +2257,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);
@@ -2356,8 +2360,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;
@@ -2366,7 +2375,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(' ');