RS ^-anchoring needs to know if it's reading the first record of a file.
authormillert <millert@openbsd.org>
Mon, 19 Apr 2021 14:08:55 +0000 (14:08 +0000)
committermillert <millert@openbsd.org>
Mon, 19 Apr 2021 14:08:55 +0000 (14:08 +0000)
Without this fix, when reading the first record of an input file named
on the command line, the regular expression engine will be
misconfigured, precluding a successful match.  From Miguel Pineiro Jr

usr.bin/awk/lib.c

index 8cbdd6d..6ae55da 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: lib.c,v 1.44 2020/12/18 21:36:24 millert Exp $        */
+/*     $OpenBSD: lib.c,v 1.45 2021/04/19 14:08:55 millert Exp $        */
 /****************************************************************
 Copyright (C) Lucent Technologies 1997
 All Rights Reserved
@@ -174,6 +174,7 @@ int getrec(char **pbuf, int *pbufsize, bool isrecord)       /* get next input record *
                                infile = stdin;
                        else if ((infile = fopen(file, "r")) == NULL)
                                FATAL("can't open file %s", file);
+                       innew = true;
                        setfval(fnrloc, 0.0);
                }
                c = readrec(&buf, &bufsize, infile, innew);