diff --git a/src/winio.c b/src/winio.c
index df3d1791f02ef7d3d9e57a10f877b060c7c93e6e..a86f771de47b548477f4ac5e5f2819641a4725d1 100644
--- a/src/winio.c
+++ b/src/winio.c
@@ -2340,7 +2340,7 @@ char *display_string(const char *buf, size_t start_col, size_t len, bool
 #endif
     }
 
-    while (index < alloc_len && buf[start_index] != '\0') {
+    while (index < alloc_len - 1 && buf[start_index] != '\0') {
 	int wide_buf, wide_buf_len;
 #ifdef NANO_WIDE
 	bool bad_char;
@@ -2449,7 +2449,7 @@ char *display_string(const char *buf, size_t start_col, size_t len, bool
 	start_index += wide_buf_len;
     }
 
-    if (index < alloc_len)
+    if (index < alloc_len - 1)
 	converted[index] = '\0';
 
     /* Make sure converted takes up no more than len columns. */