From 22a86ef2881f50b132e2c25098304546903bb898 Mon Sep 17 00:00:00 2001 From: millert Date: Thu, 10 Jun 2021 21:01:43 +0000 Subject: [PATCH] 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 --- usr.bin/awk/lib.c | 5 +++-- 1 file 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; } -- 2.20.1