diff --git a/src/winio.c b/src/winio.c
index 17b258bd2e4f2ca9e0d1b49569c361b7308d4338..a89b2aa09a7342e39b8a8a13370840fe0027a408 100644
--- a/src/winio.c
+++ b/src/winio.c
@@ -1902,7 +1902,7 @@ char *display_string(const char *buf, size_t column, size_t span, bool isdata)
 		converted[index++] = ' ';
 	    column++;
 	    /* Fill the tab up with the required number of spaces. */
-	    while (column % tabsize != 0) {
+	    while (column % tabsize != 0 && column < beyond) {
 		converted[index++] = ' ';
 		column++;
 	    }