From cf6fe9a41e8f82c9c336f0320c5167001787b4b7 Mon Sep 17 00:00:00 2001 From: Martijn van Duren Date: Mon, 17 Aug 2020 18:41:24 +0000 Subject: -F requires at least 5 columns for folding, while a tab at start of line is 8 columns. This causes an infinite loop in the folding logic. Fix this by implementing an escape hatch so that only a single fold can occur. This does mean that a tab with a -F smaller or equal to 8 will always print the newline escape backslash in the 8th column. Bug reported by phillbush cock li Minor tweak and OK deraadt@ --- usr.bin/vis/foldit.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'usr.bin/vis') diff --git a/usr.bin/vis/foldit.c b/usr.bin/vis/foldit.c index f9abd9963f2..aaa05922a61 100644 --- a/usr.bin/vis/foldit.c +++ b/usr.bin/vis/foldit.c @@ -1,4 +1,4 @@ -/* $OpenBSD: foldit.c,v 1.7 2013/11/12 22:51:18 deraadt Exp $ */ +/* $OpenBSD: foldit.c,v 1.8 2020/08/17 18:41:23 martijn Exp $ */ /* $NetBSD: foldit.c,v 1.4 1994/12/20 16:13:02 jtc Exp $ */ /*- @@ -38,6 +38,7 @@ int foldit(char *chunk, int col, int max) { char *cp; + int first = (col != 0); /* * Keep track of column position. Insert hidden newline @@ -61,8 +62,11 @@ again: col++; } if (col > (max - 2)) { + if (!first) + return (col); printf("\\\n"); col = 0; + first = 0; goto again; } cp++; -- cgit v1.2.3