Fix multiple long-standing bugs, improve test suite.
diff --git a/lib.c b/lib.c
index 1b6d86e..ba6ebd4 100644
--- a/lib.c
+++ b/lib.c
@@ -356,6 +356,7 @@
 		}
 	}
 	setfval(nfloc, (Awkfloat) lastfld);
+	donerec = 1; /* restore */
 	if (dbg) {
 		for (j = 0; j <= lastfld; j++) {
 			p = fldtab[j];
@@ -387,6 +388,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)