Subject: bin/29358: awk produces bogus output
To: None <gnats-admin@netbsd.org, netbsd-bugs@netbsd.org>
From: None <john@iastate.edu>
List: netbsd-bugs
Date: 02/13/2005 19:40:00
>Number:         29358
>Category:       bin
>Synopsis:       awk produces bogus output
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Feb 13 19:40:00 +0000 2005
>Originator:     john@iastate.edu
>Release:        NetBSD 2.0
>Organization:
	Iowa State University
>Environment:
System: NetBSD malapert.ait.iastate.edu 2.0 NetBSD 2.0 (GENERIC) #0: Wed Dec 1 10:58:25 UTC 2004 builds@build:/big/builds/ab/netbsd-2-0-RELEASE/i386/200411300000Z-obj/big/builds/ab/netbsd-2-0-RELEASE/src/sys/arch/i386/compile/GENERIC i386
Architecture: i386
Machine: i386
>Description:
	awk produces incorrect output
>How-To-Repeat:
	Given the script below:

#!/bin/sh
(cat $1; echo x: xmap.o) | \
        sed 's/\.c/.o/g' | \
        awk '-F[[:space:]]*:[[:space:]]*' \
            'BEGIN {printf "all: $(ALL)\n$(ALL):"} \
                   {printf " %s",$2} \
             END   {printf "\n\tar cruvs $(ALL) \$?\n\n"}
             END   {printf "xmap.o: xmap.c xmap.h\n"}
             END   {printf "\n"}
             END   {printf "xmap.h::\n"}
             END   {printf "\t./makexmap.sh modules.map > xmap.h\n"}'


And the following sample input file (argv[1] to the script) contents:

admin.so:               blocked.c exempt.c licenses.c


The following (incorrect) output is produced (see the end of the 2nd line):

all: $(ALL)
$(ALL): blocked.o exempt.o licenses.o x
        ar cruvs $(ALL) $?

xmap.o: xmap.c xmap.h

xmap.h::
        ./makexmap.sh modules.map > xmap.h


If the "x:" in the first line of the script is replaced with "xy:"
a different incorrect output is produced:

all: $(ALL)
$(ALL): blocked.o exempt.o licenses.o
        ar cruvs $(ALL) $?

xmap.o: xmap.c xmap.h

xmap.h::
        ./makexmap.sh modules.map > xmap.h


And using "xyz:" a third incorrect output is produced:

all: $(ALL)
$(ALL): blocked.o exempt.o licenses.o n.so
        ar cruvs $(ALL) $?

xmap.o: xmap.c xmap.h

xmap.h::
        ./makexmap.sh modules.map > xmap.h


Finally, using a long enough, say "wxyz:" produces correct
output:

all: $(ALL)
$(ALL): blocked.o exempt.o licenses.o xmap.o
        ar cruvs $(ALL) $?

xmap.o: xmap.c xmap.h

xmap.h::
        ./makexmap.sh modules.map > xmap.h


>Fix: