Bug 14529

Summary: Re: awk -v var=val coredump
Product: Base System Reporter: Aharon Robbins <arnold>
Component: binAssignee: GNATS administrator <gnats-admin>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: 1.0-RELEASE   
Hardware: Any   
OS: Any   

Description Aharon Robbins 1999-10-26 04:00:01 UTC
 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
Comment 1 Steve Price freebsd_committer freebsd_triage 1999-11-07 21:54:33 UTC
State Changed
From-To: open->closed

Followup to gnu/13921.