From jin@iss-p5.lbl.gov Thu Sep 23 12:47:09 1999
Return-Path: <jin@iss-p5.lbl.gov>
Received: from iss-p5.lbl.gov (iss-p5.lbl.gov [131.243.2.30])
	by hub.freebsd.org (Postfix) with ESMTP id 22D3B14ECC
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 23 Sep 1999 12:47:02 -0700 (PDT)
	(envelope-from jin@iss-p5.lbl.gov)
Received: (from jin@localhost)
	by iss-p5.lbl.gov (8.9.3/8.9.3) id MAA39579;
	Thu, 23 Sep 1999 12:46:01 -0700 (PDT)
	(envelope-from jin)
Message-Id: <199909231946.MAA39579@iss-p5.lbl.gov>
Date: Thu, 23 Sep 1999 12:46:01 -0700 (PDT)
From: Jin Guojun (FTG staff) <jin@iss-p5.lbl.gov>
Reply-To: j_guojun@lbl.gov
To: FreeBSD-gnats-submit@freebsd.org, bug-gnu-utils@prep.ai.mit.edu
Cc: arnold@gnu.ai.mit.edu
Subject: awk -v var=val coredump
X-Send-Pr-Version: 3.2

>Number:         13921
>Category:       gnu
>Synopsis:       awk -v var=val coredump
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    sheldonh
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Sep 23 12:50:01 PDT 1999
>Closed-Date:    Tue Nov 27 10:25:46 PST 2001
>Last-Modified:  Tue Nov 27 10:26:41 PST 2001
>Originator:     Jin Guojun (FTG staff)
>Release:        FreeBSD 3.3-RELEASE i386
>Organization:
>Environment:

	All GNU awk on all platforms

>Description:

	awk -v NF=name
awk: fatal error: internal error
Abort (core dumped)

>How-To-Repeat:

	simply type this command with/without any input

		awk -v NF=name

>Fix:
	
	


>Release-Note:
>Audit-Trail:

From: Sheldon Hearn <sheldonh@uunet.co.za>
To: j_guojun@lbl.gov
Cc: FreeBSD-gnats-submit@FreeBSD.ORG
Subject: Re: gnu/13921: awk -v var=val coredump 
Date: Mon, 27 Sep 1999 08:52:16 +0200

 On Thu, 23 Sep 1999 12:46:01 MST, Jin Guojun wrote:
 
 > 	All GNU awk on all platforms
 
 If this is a bug in gawk-3.0.4, I'd prefer to close your FreeBSD PR and
 leave this for the gawk maintainer.
 
 Let me know.
 
 Thanks,
 Sheldon.
 

From arnold@skeeve.com Sat Oct 23 21:07:18 1999
Date: Fri, 22 Oct 1999 17:56:35 +0200
From: Aharon Robbins <arnold@skeeve.com>
To: jin@iss-p5.lbl.gov
Cc: bug-gnu-utils@gnu.org, FreeBSD-gnats-submit@freebsd.org
Subject: Re: awk -v var=val coredump

 Hi.  Concerning this:
 
 > 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
 
 By the way, not all `-v var=val' leads to core dumping.  Just (I think) NF.
 
 > 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)
 >
 > >How-To-Repeat: 
 >
 > 	simply type this command with/without any input
 >
 > 		awk -v NF=name
 >
 > >Fix: 
 
 This is not a pretty thing to fix.  Even with this, gawk does not
 print `name' as the result, but 0, since when the BEGIN block is run,
 there isn't yet a record, so the number of fields is 0.  In this, gawk
 is now in agreement with Brian Kernighan's awk, so at least I'm in
 good company. (:-)
 
 What the semantics of `-v NF=name' "ought" to be, I dunno, but the
 nawk/fixed-gawk behavior is at least reasonable.
 
 Here is a patch and ChangeLog entries.  This includes also a fix so
 that arguments of the form `./3x=foo' are silently treated as filenames,
 instead of as fatal errors.
 
 Enjoy,
 
 Arnold Robbins
 -----------------------------------------------------------------
 Fri Oct 22 17:43:40 1999  Arnold D. Robbins  <arnold@skeeve.com>
 
 	* main.c (arg_assign): Add new arg, `initing' for icky special
 	  casing of -v of special variables.  Use it to check for NF.
 	  May need to add other cases later.
 	  (pre_assign): change call arg_assign, passing initing=TRUE;
 	  io.c (nextfile): change call arg_assign, passing initing=FALSE;
 	  awk.h: Change prototype for arg_assign.
 
 Wed Oct  6 17:47:47 1999  Arnold D. Robbins  <arnold@skeeve.com>
 
 	* main.c (arg_assign): return NULL on bad variable.  Allows
 	  things like `./3x=stuff' to work as a filename.
 
 *** ../gawk-3.0.4/awk.h	Wed Jun 30 16:06:13 1999
 --- awk.h	Fri Oct 22 17:09:52 1999
 ***************
 *** 810,816 ****
   /* main.c */
   extern int main P((int argc, char **argv));
   extern void load_environ P((void));
 ! extern char *arg_assign P((char *arg));
   extern RETSIGTYPE catchsig P((int sig, int code));
   /* msg.c */
   extern void err P((const char *s, const char *emsg, va_list argp));
 --- 813,819 ----
   /* main.c */
   extern int main P((int argc, char **argv));
   extern void load_environ P((void));
 ! extern char *arg_assign P((char *arg, int initing));
   extern RETSIGTYPE catchsig P((int sig, int code));
   /* msg.c */
   extern void err P((const char *s, const char *emsg, va_list argp));
 *** ../gawk-3.0.4/main.c	Mon May  3 13:24:45 1999
 --- main.c	Fri Oct 22 17:43:28 1999
 ***************
 *** 629,636 ****
   /* arg_assign --- process a command-line assignment */
   
   char *
 ! arg_assign(arg)
   char *arg;
   {
   	char *cp, *cp2;
   	int badvar;
 --- 629,637 ----
   /* arg_assign --- process a command-line assignment */
   
   char *
 ! arg_assign(arg, initing)
   char *arg;
 + int initing;
   {
   	char *cp, *cp2;
   	int badvar;
 ***************
 *** 652,659 ****
   					badvar = TRUE;
   					break;
   				}
 ! 		if (badvar)
 ! 			fatal("illegal name `%s' in variable assignment", arg);
   
   		/*
   		 * Recent versions of nawk expand escapes inside assignments.
 --- 653,665 ----
   					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.
 ***************
 *** 662,668 ****
   		it = make_str_node(cp, strlen(cp), SCAN);
   		it->flags |= (MAYBE_NUM|SCALAR);
   		var = variable(arg, FALSE, Node_var);
 ! 		lhs = get_lhs(var, &after_assign);
   		unref(*lhs);
   		*lhs = it;
   		if (after_assign != NULL)
 --- 668,681 ----
   		it = make_str_node(cp, strlen(cp), SCAN);
   		it->flags |= (MAYBE_NUM|SCALAR);
   		var = variable(arg, FALSE, Node_var);
 ! 		/* This is a hack.  Add other variables as needed. */
 ! 		if (initing) {
 ! 			if (strcmp(arg, "NF") == 0)
 ! 				lhs = &(NF_node->var_value);
 ! 			else
 ! 				lhs = get_lhs(var, &after_assign);
 ! 		} else
 ! 			lhs = get_lhs(var, &after_assign);
   		unref(*lhs);
   		*lhs = it;
   		if (after_assign != NULL)
 ***************
 *** 678,684 ****
   pre_assign(v)
   char *v;
   {
 ! 	if (arg_assign(v) == NULL) {
   		fprintf(stderr,
   			"%s: `%s' argument to `-v' not in `var=value' form\n",
   				myname, v);
 --- 691,697 ----
   pre_assign(v)
   char *v;
   {
 ! 	if (arg_assign(v, TRUE) == NULL) {
   		fprintf(stderr,
   			"%s: `%s' argument to `-v' not in `var=value' form\n",
   				myname, v);
 *** ../gawk-3.0.4/io.c	Wed Jun 30 16:08:17 1999
 --- io.c	Fri Oct 22 17:10:10 1999
 ***************
 *** 165,171 ****
   			unref(ARGIND_node->var_value);
   			ARGIND_node->var_value = make_number((AWKNUM) i);
   		}
 ! 		if (! arg_assign(arg->stptr)) {
   			files++;
   			fname = arg->stptr;
   			curfile = iop_open(fname, "r", &mybuf);
 --- 165,171 ----
   			unref(ARGIND_node->var_value);
   			ARGIND_node->var_value = make_number((AWKNUM) i);
   		}
 ! 		if (! arg_assign(arg->stptr, FALSE)) {
   			files++;
   			fname = arg->stptr;
   			curfile = iop_open(fname, "r", &mybuf);
 --
 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
 
 
From arnold@skeeve.com Mon Oct 25 19:54:46 1999
To: bug-gnu-utils@gnu.org, FreeBSD-gnats-submit@freebsd.org,
	jin@iss-p5.lbl.gov
Subject: Re: awk -v var=val coredump

 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
 
 
State-Changed-From-To: open->analyzed 
State-Changed-By: sheldonh 
State-Changed-When: Tue Aug 15 03:55:02 PDT 2000 
State-Changed-Why:  
gawk-3.0.6 imported on the vendor branch and merged onto 
HEAD.  We'll merge it onto RELENG_4 soon. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=13921 
Responsible-Changed-From-To: freebsd-bugs->sheldonh 
Responsible-Changed-By: sheldonh 
Responsible-Changed-When: Tue Aug 15 07:32:43 PDT 2000 
Responsible-Changed-Why:  
My reminder. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=13921 
State-Changed-From-To: analyzed->closed 
State-Changed-By: sheldonh 
State-Changed-When: Tue Nov 27 10:25:46 PST 2001 
State-Changed-Why:  
gawk-3.0.6 was merged onto the RELENG_4 branch on 2000/08/15! 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=13921 
>Unformatted:
