[Toybox] Sigh. Anybody spot the bug?

Felix Janda felix.janda at posteo.de
Fri Jul 19 06:00:17 PDT 2013


Rob Landley wrote:
[...]
> > than count*sizeof(toybuf) and contain no newlines.
> 
> Count is initialized in a for loop and starts at 0 on line 164 so I  
> dunno what this means...

Sorry for the confusion. I meant the number of lines tail is told to
output.

[...]
> > diff -r f8db1f6ec4ab toys/posix/tail.c
> > --- a/toys/posix/tail.c	Tue Jul 02 00:16:16 2013 -0500
> > +++ b/toys/posix/tail.c	Wed Jul 03 20:54:24 2013 +0200
> > @@ -168,7 +168,7 @@
> >          }
> > 
> >          if (lines) {
> > -          if(try[count] != '\n' && count != len-1) continue;
> > +          if(try[count] != '\n') continue;
> 
> Hmmm, I believe that's related to getting the line count right when the  
> last line doesn't end with a newline? But I don't remember the  
> details...

See Isaac's replies in this topic. The current condition is just wrong:

$ cat toys.h toys.h toys.h | tail | wc -l
9

This is fixed with the patch. However in some situations it still gives
wrong output since other code still assumes that there are newlines at
the end of each sizeof(toybuf) piece. Maybe it's simpler to rewrite this
part...

Felix

 1374238817.0


More information about the Toybox mailing list