[net.unix-wizards] Awk and VAX 4.2 BSD

rbbb@RICE.ARPA (06/25/84)

From:  David Chase <rbbb@RICE.ARPA>

This message Copyright (C) 1984 by David R. Chase.
May not be distributed for profit.

Problem: awk is broken.

Proof:  The following one-liner
	echo "This is a test" | awk '{$1 = "That"; print}'
prints  "This is a test" instead of "That is a test"

To fix this bug (I think):
in the file "tran.c", replace every occurrence (there are two) of 
	if ((vp->tval & FLD) && vp->nval == 0)
with 
	if ((vp->tval & FLD) && (vp->nval == 0 ? 1 :  *(vp->nval) == 0))
You should find these in the routines setsval and setfval.

Explanation:  In a vp -> nval is a character string.  Someone tried to fix
awk to remove all assumptions that *0 == 0; as part of this effort, the
routine "stringto" returns an allocated empty string (why not a single
empty string??) whenever it is passed zero as input.  Furthermore, most
references to NULL were changed into references to a static string EMPTY.
The test for null string "vp->nval == 0" fails because the conversion was
incomplete.  My fix is (I hope) very conservative, and in the worst case
makes awk run a little slower than it should.

drc