From 622995fb1240c56014c1599197067655931add84 Mon Sep 17 00:00:00 2001
From: Benno Schulenberg <bensberg@justemail.net>
Date: Wed, 29 Jun 2016 20:37:28 +0200
Subject: [PATCH] chars: the representation of a control character is always
 two bytes

Any control character is represented by a ^ plus an ASCII character.
---
 src/chars.c | 19 ++++++-------------
 src/proto.h |  2 +-
 src/winio.c | 31 +++++--------------------------
 3 files changed, 12 insertions(+), 40 deletions(-)

diff --git a/src/chars.c b/src/chars.c
index 97ed921b..9e839036 100644
--- a/src/chars.c
+++ b/src/chars.c
@@ -253,27 +253,20 @@ wchar_t control_wrep(wchar_t wc)
 }
 #endif
 
-/* c is a multibyte control character.  It displays as ^@, ^?, or ^[ch],
- * where ch is (c + 64).  We return that single-byte character. */
-char *control_mbrep(const char *c, char *crep, int *crep_len)
+/* Return the visible representation of multibyte control character c. */
+char control_mbrep(const char *c)
 {
-    assert(c != NULL && crep != NULL && crep_len != NULL);
+    assert(c != NULL);
 
 #ifdef ENABLE_UTF8
     if (use_utf8) {
 	if (0 <= c[0] && c[0] <= 127)
-	    *crep = control_rep(c[0]);
+	    return control_rep(c[0]);
 	else
-	    *crep = control_rep(c[1]);
-	*crep_len = 1;
+	    return control_rep(c[1]);
     } else
 #endif
-    {
-	*crep_len = 1;
-	*crep = control_rep(*c);
-    }
-
-    return crep;
+	return control_rep(*c);
 }
 
 /* c is a multibyte non-control character.  We return that multibyte
diff --git a/src/proto.h b/src/proto.h
index 9581848b..14bb0405 100644
--- a/src/proto.h
+++ b/src/proto.h
@@ -193,7 +193,7 @@ char control_rep(const signed char c);
 #ifdef ENABLE_UTF8
 wchar_t control_wrep(wchar_t wc);
 #endif
-char *control_mbrep(const char *c, char *crep, int *crep_len);
+char control_mbrep(const char *c);
 char *mbrep(const char *c, char *crep, int *crep_len);
 int mbwidth(const char *c);
 int mb_cur_max(void);
diff --git a/src/winio.c b/src/winio.c
index d7494576..df7453c1 100644
--- a/src/winio.c
+++ b/src/winio.c
@@ -1786,18 +1786,8 @@ char *display_string(const char *buf, size_t start_col, size_t len, bool
 
 	if (is_cntrl_mbchar(buf_mb)) {
 	    if (column < start_col) {
-		char *character = charalloc(mb_cur_max());
-		int charlen, i;
-
-		character = control_mbrep(buf_mb, character, &charlen);
-
-		for (i = 0; i < charlen; i++)
-		    converted[index++] = character[i];
-
-		start_col += mbwidth(character);
-
-		free(character);
-
+		converted[index++] = control_mbrep(buf_mb);
+		start_col++;
 		start_index += buf_mb_len;
 	    }
 	}
@@ -1859,22 +1849,11 @@ char *display_string(const char *buf, size_t start_col, size_t len, bool
 		converted[index++] = ' ';
 		start_col++;
 	    }
-	/* If buf contains a control character, interpret it. */
+	/* If buf contains a control character, represent it. */
 	} else if (is_cntrl_mbchar(buf_mb)) {
-	    char *character = charalloc(mb_cur_max());
-	    int charlen, i;
-
 	    converted[index++] = '^';
-	    start_col++;
-
-	    character = control_mbrep(buf_mb, character, &charlen);
-
-	    for (i = 0; i < charlen; i++)
-		converted[index++] = character[i];
-
-	    start_col += mbwidth(character);
-
-	    free(character);
+	    converted[index++] = control_mbrep(buf_mb);
+	    start_col += 2;
 	/* If buf contains a non-control character, interpret it.  If buf
 	 * contains an invalid multibyte sequence, display it as such. */
 	} else {
-- 
GitLab