Hi,

If we bump 'line' from an int to an unsigned long long we will
correctly number files with more than INT_MAX lines instead of
wrapping to a negative number.

ok?

Index: cat.c
===================================================================
RCS file: /cvs/src/bin/cat/cat.c,v
retrieving revision 1.30
diff -u -p -r1.30 cat.c
--- cat.c       4 Dec 2020 02:25:56 -0000       1.30
+++ cat.c       11 Dec 2020 04:10:51 -0000
@@ -132,7 +132,8 @@ cook_args(char **argv)
 void
 cook_buf(FILE *fp, const char *filename)
 {
-       int ch, gobble, line, prev;
+       unsigned long long line;
+       int ch, gobble, prev;
 
        line = gobble = 0;
        for (prev = '\n'; (ch = getc(fp)) != EOF; prev = ch) {
@@ -147,7 +148,7 @@ cook_buf(FILE *fp, const char *filename)
                        }
                        if (nflag) {
                                if (!bflag || ch != '\n') {
-                                       (void)fprintf(stdout, "%6d\t", ++line);
+                                       fprintf(stdout, "%6llu\t", ++line);
                                        if (ferror(stdout))
                                                break;
                                } else if (eflag) {

Reply via email to