The following command makes vis(1) go through an infinite loop.
$ printf 'a\tb' | vis -F8
The problem is a goto in usr.bin/vis/foldit.c
I think that the following diff fixes this, but I am not confident
enough.
--- a/vis/foldit.c Fri Aug 14 14:08:47 2020
+++ b/vis/foldit.c Fri Aug 14 14:01:15 2020
@@ -38,34 +38,37 @@ int
foldit(char *chunk, int col, int max)
{
char *cp;
+ int newcol;
/*
* Keep track of column position. Insert hidden newline
* if this chunk puts us over the limit.
*/
-again:
- cp = chunk;
- while (*cp) {
+ newcol = 0;
+ for (cp = chunk; *cp; cp++) {
switch(*cp) {
case '\n':
case '\r':
- col = 0;
+ newcol = col = 0;
break;
case '\t':
col = (col + 8) & ~07;
+ newcol = (newcol + 8) & ~07;
break;
case '\b':
col = col ? col - 1 : 0;
+ newcol = newcol ? newcol - 1 : 0;
break;
default:
col++;
+ newcol++;
}
- if (col > (max - 2)) {
- printf("\\\n");
- col = 0;
- goto again;
- }
- cp++;
}
+
+ if (col > (max - 2)) {
+ printf("\\\n");
+ col = newcol;
+ }
+
return (col);
}