Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/external/historical/nawk/dist PR/44063: Aleksey Cheusov: awk...
details: https://anonhg.NetBSD.org/src/rev/18ca3e060ab7
branches: trunk
changeset: 758554:18ca3e060ab7
user: christos <christos%NetBSD.org@localhost>
date: Sun Nov 07 22:55:26 2010 +0000
description:
PR/44063: Aleksey Cheusov: awk: setting NF doesn't change $i
http://www.opengroup.org/onlinepubs/009695399/utilities/awk.html
...
References to nonexistent fields (that is, fields after $NF),
shall evaluate to the uninitialized value.
diffstat:
external/historical/nawk/dist/lib.c | 14 ++++++++++++++
external/historical/nawk/dist/proto.h | 1 +
external/historical/nawk/dist/tran.c | 13 +++++++++++++
3 files changed, 28 insertions(+), 0 deletions(-)
diffs (79 lines):
diff -r bd6d102363cc -r 18ca3e060ab7 external/historical/nawk/dist/lib.c
--- a/external/historical/nawk/dist/lib.c Sun Nov 07 21:41:38 2010 +0000
+++ b/external/historical/nawk/dist/lib.c Sun Nov 07 22:55:26 2010 +0000
@@ -400,6 +400,7 @@
}
}
setfval(nfloc, (Awkfloat) lastfld);
+ donerec = 1; /* restore */
if (dbg) {
for (j = 0; j <= lastfld; j++) {
p = fldtab[j];
@@ -431,6 +432,19 @@
setfval(nfloc, (Awkfloat) n);
}
+void setlastfld(int n) /* set lastfld cleaning fldtab cells if necessary */
+{
+ if (n > nfields)
+ growfldtab(n);
+
+ if (lastfld < n)
+ cleanfld(lastfld+1, n);
+ else
+ cleanfld(n+1, lastfld);
+
+ lastfld = n;
+}
+
Cell *fieldadr(int n) /* get nth field */
{
if (n < 0)
diff -r bd6d102363cc -r 18ca3e060ab7 external/historical/nawk/dist/proto.h
--- a/external/historical/nawk/dist/proto.h Sun Nov 07 21:41:38 2010 +0000
+++ b/external/historical/nawk/dist/proto.h Sun Nov 07 22:55:26 2010 +0000
@@ -127,6 +127,7 @@
extern void fldbld(void);
extern void cleanfld(int, int);
extern void newfld(int);
+extern void setlastfld(int);
extern int refldbld(const char *, const char *);
extern void recbld(void);
extern Cell *fieldadr(int);
diff -r bd6d102363cc -r 18ca3e060ab7 external/historical/nawk/dist/tran.c
--- a/external/historical/nawk/dist/tran.c Sun Nov 07 21:41:38 2010 +0000
+++ b/external/historical/nawk/dist/tran.c Sun Nov 07 22:55:26 2010 +0000
@@ -298,6 +298,10 @@
if (fldno > *NF)
newfld(fldno);
dprintf( ("setting field %d to %g\n", fldno, f) );
+ } else if (&vp->fval == NF) {
+ donerec = 0; /* mark $0 invalid */
+ setlastfld(f);
+ dprintf( ("setting NF to %g\n", f) );
} else if (isrec(vp)) {
donefld = 0; /* mark $1... invalid */
donerec = 1;
@@ -324,6 +328,7 @@
{
char *t;
int fldno;
+ Awkfloat f;
dprintf( ("starting setsval %p: %s = \"%s\", t=%o, r,f=%d,%d\n",
vp, NN(vp->nval), s, vp->tval, donerec, donefld) );
@@ -347,6 +352,14 @@
vp->tval &= ~DONTFREE;
dprintf( ("setsval %p: %s = \"%s (%p) \", t=%o r,f=%d,%d\n",
vp, NN(vp->nval), t,t, vp->tval, donerec, donefld) );
+
+ if (&vp->fval == NF) {
+ donerec = 0; /* mark $0 invalid */
+ f = getfval(vp);
+ setlastfld(f);
+ dprintf( ("setting NF to %g\n", f) );
+ }
+
return(vp->sval = t);
}
Home |
Main Index |
Thread Index |
Old Index