It would help if you could add some more information on where the bug 
occurs and how this fixes the issue.

This doesn't only help the developers understand the bug quicker, but
also help you gain confidence in your code because you write out what
the problem really is.

But thanks for pointing this out.

Since foldit seems to be intended to determine if a row is full before a
printing it and add a new line if it would overflow it's logical that
a foldwidth of <= 8 and a tab will overflow it.

There's two ways to approach this:
1) -F has a check for < 5, which we could raise to 8 to get \t to fit.
2) Determine \t is dynamic between 1 and 8 columns, so just state that
   if we overflow don't bother and just continue to the next line.
   Downside of this approach is that the '\' will be outside the
   requested fold range.

Personally I like the second one better, so here's a quick diff to
do so. Only lightly tested.

OK?

martijn@

On Fri, 2020-08-14 at 17:15 +0000, [email protected] wrote:
> 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.
> 
Index: foldit.c
===================================================================
RCS file: /cvs/src/usr.bin/vis/foldit.c,v
retrieving revision 1.7
diff -u -p -r1.7 foldit.c
--- foldit.c    12 Nov 2013 22:51:18 -0000      1.7
+++ foldit.c    15 Aug 2020 14:03:12 -0000
@@ -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++;

Reply via email to