From arnold@skeeve.com Mon Oct 25 19:54:46 1999
Return-Path: <arnold@skeeve.com>
Received: from cascadia.a42.com (cascadia.a42.com [216.39.159.18])
	by hub.freebsd.org (Postfix) with ESMTP id 1EC4D14E0F
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 25 Oct 1999 19:54:43 -0700 (PDT)
	(envelope-from arnold@skeeve.com)
Received: from 192.168.1.38 (passenger.ssc.com [216.39.159.17])
	by cascadia.a42.com (8.9.1a/8.8.5) with SMTP id TAA01555;
	Mon, 25 Oct 1999 19:55:13 -0700
Message-Id: <199910260255.TAA01555@cascadia.a42.com>
Date: Mon, 25 Oct 1999 18:44:31 +0200
From: Aharon Robbins <arnold@skeeve.com>
To: bug-gnu-utils@gnu.org, FreeBSD-gnats-submit@freebsd.org,
	jin@iss-p5.lbl.gov
Subject: Re: awk -v var=val coredump

>Number:         14529
>Category:       bin
>Synopsis:       Re: awk -v var=val coredump
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    gnats-admin
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Oct 25 20:00:01 PDT 1999
>Closed-Date:    Sun Nov 7 13:54:33 PST 1999
>Last-Modified:  Wed Oct 26 06:03:25 GMT 2005
>Originator:     
>Release:        
>Organization:
>Environment:
>Description:
 Greetings.  Earlier, I submitted a rather convoluted patch for
 this bug report:
 
 > > Date: Thu, 23 Sep 1999 12:46:01 -0700 (PDT)
 > > From: Jin Guojun (FTG staff) <jin@iss-p5.lbl.gov>
 > > To: FreeBSD-gnats-submit@freebsd.org, bug-gnu-utils@gnu.org
 > > Subject: awk -v var=val coredump
 > > Cc: arnold@gnu.org
 > >
 > > >Submitter-Id:   current-users
 > > >Originator:     Jin Guojun (FTG staff)
 > > >Organization:   
 > > >Confidential:   no
 > > >Synopsis:       awk -v var=val coredump
 > > >Severity:       non-critical
 > > >Priority:       medium
 > > >Category:       gnu
 > > >Release:        FreeBSD 3.3-RELEASE i386
 > > >Class:          sw-bug
 > > >Environment: 
 > >
 > > 	All GNU awk on all platforms
 > >
 > > >Description: 
 > >
 > > 	awk -v NF=name
 > > awk: fatal error: internal error
 > > Abort (core dumped)
 
 Here is a much better patch.  Again, this is against stock 3.0.4
 sources.  It also includes the fix for filenames that contain `='
 but that aren't valid assignment statements.
 
 Sorry for the double fix, but this is definitely better code.
 
 Even better,
 
 	gawk -v NF=name 'BEGIN { print NF }'
 
 now prints `name'.
 
 Arnold
 -------------------------------------------
 *** ../gawk-3.0.4/main.c	Mon May  3 03:24:45 1999
 --- main.c	Mon Oct 25 18:36:51 1999
 ***************
 *** 175,184 ****
   	/* Set up the special variables */
   	/*
   	 * Note that this must be done BEFORE arg parsing else -F
 ! 	 * breaks horribly 
   	 */
   	init_vars();
   
   	/* worst case */
   	emalloc(srcfiles, struct src *, argc * sizeof(struct src), "main");
   	memset(srcfiles, '\0', argc * sizeof(struct src));
 --- 175,191 ----
   	/* Set up the special variables */
   	/*
   	 * Note that this must be done BEFORE arg parsing else -F
 ! 	 * breaks horribly.
   	 */
   	init_vars();
   
 + 	/* Set up the field variables */
 + 	/*
 + 	 * Do this before arg parsing so that `-v NF=blah' won't
 + 	 * break anything.
 + 	 */
 + 	init_fields();
 + 
   	/* worst case */
   	emalloc(srcfiles, struct src *, argc * sizeof(struct src), "main");
   	memset(srcfiles, '\0', argc * sizeof(struct src));
 ***************
 *** 377,385 ****
   	(void) alloca(0);
   #endif
   
 - 	/* Set up the field variables */
 - 	init_fields();
 - 
   	if (do_lint && begin_block == NULL && expression_value == NULL
   	     && end_block == NULL)
   		warning("no program");
 --- 384,389 ----
 ***************
 *** 652,659 ****
   					badvar = TRUE;
   					break;
   				}
 ! 		if (badvar)
 ! 			fatal("illegal name `%s' in variable assignment", arg);
   
   		/*
   		 * Recent versions of nawk expand escapes inside assignments.
 --- 656,668 ----
   					badvar = TRUE;
   					break;
   				}
 ! 
 ! 		if (badvar) {
 ! 			if (do_lint)
 ! 				warning("illegal name `%s' in variable assignment", arg);
 ! 			*--cp = '=';	/* restore original text of ARGV */
 ! 			return NULL;
 ! 		}
   
   		/*
   		 * Recent versions of nawk expand escapes inside assignments.
 --
 Aharon (Arnold) Robbins		arnold@skeeve.com  [ <<=== NOTE: NEW ADDRESS!! ]
 P.O. Box 354		Home Phone: +972  8 979-0381	Fax: +1 603 761-6761
 Nof Ayalon		Cell Phone: +972 51  297-545	(See www.efax.com)
 D.N. Shimshon 99784	Laundry increases exponentially in the
 ISRAEL			number of children. -- Miriam Robbins
 
 
>How-To-Repeat:
>Fix:
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: steve 
State-Changed-When: Sun Nov 7 13:54:33 PST 1999 
State-Changed-Why:  
Followup to gnu/13921. 
>Unformatted:
