diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2021-06-10 21:01:44 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2021-06-10 21:01:44 +0000 |
commit | 8cf96700690382e2225de03c7c5e52058417eda1 (patch) | |
tree | 9c3dc794d500cf9df6f90eebd802ff079a39081e /usr.bin/awk | |
parent | 5b68b09712963bcbba748e61cc991568cecdc6b6 (diff) |
Fix readrec's definition of a record
It is not sufficient to check for the EOF flag on a stream.
From https://github.com/onetrueawk/awk/pull/117
Diffstat (limited to 'usr.bin/awk')
-rw-r--r-- | usr.bin/awk/lib.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/usr.bin/awk/lib.c b/usr.bin/awk/lib.c index 6ae55dab4f4..cd84399c9b0 100644 --- a/usr.bin/awk/lib.c +++ b/usr.bin/awk/lib.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lib.c,v 1.45 2021/04/19 14:08:55 millert Exp $ */ +/* $OpenBSD: lib.c,v 1.46 2021/06/10 21:01:43 millert Exp $ */ /**************************************************************** Copyright (C) Lucent Technologies 1997 All Rights Reserved @@ -240,6 +240,7 @@ int readrec(char **pbuf, int *pbufsize, FILE *inf, bool newflag) /* read one rec } if (found) setptr(patbeg, '\0'); + isrec = (found == 0 && *buf == '\0') ? 0 : 1; } else { if ((sep = *rs) == 0) { sep = '\n'; @@ -269,10 +270,10 @@ int readrec(char **pbuf, int *pbufsize, FILE *inf, bool newflag) /* read one rec if (!adjbuf(&buf, &bufsize, 1+rr-buf, recsize, &rr, "readrec 3")) FATAL("input record `%.30s...' too long", buf); *rr = 0; + isrec = (c == EOF && rr == buf) ? 0 : 1; } *pbuf = buf; *pbufsize = bufsize; - isrec = *buf || !feof(inf); DPRINTF("readrec saw <%s>, returns %d\n", buf, isrec); return isrec; } |