]> err.no Git - util-linux/commitdiff
column: EOF handling bug
authorSami Kerola <kerolasa@iki.fi>
Sat, 9 Oct 2010 17:59:48 +0000 (19:59 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 21 Oct 2010 07:38:17 +0000 (09:38 +0200)
For the last line of the file lenght of line should be determined
where the EOF is instead of new line. Old output was

$ printf "1 2\n3" | column -t
column: line too long
1 2

which this commit will change to

$ printf "1 2\n3" | column -t
1  2
3

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
text-utils/column.c

index e7cd334649e99bd60a84c0837de2f34c309e776a..c8c40664ade9a7e1732fa110f10c5397febd5f2d 100644 (file)
@@ -322,12 +322,13 @@ input(fp)
                for (p = buf; *p && iswspace(*p); ++p);
                if (!*p)
                        continue;
-               if (!(p = wcschr(p, '\n'))) {
+               if (!(p = wcschr(p, '\n')) && !feof(fp)) {
                        warnx(_("line too long"));
                        eval = 1;
                        continue;
                }
-               *p = '\0';
+               if (!feof(fp))
+                       *p = '\0';
                len = wcs_width(buf);   /* len = p - buf; */
                if (maxlength < len)
                        maxlength = len;