From arnold@skeeve.com Sat Oct 23 21:07:18 1999
Return-Path: <arnold@skeeve.com>
Received: from moe.cc.emory.edu (moe.cc.emory.edu [170.140.1.67])
	by hub.freebsd.org (Postfix) with ESMTP id ADB46150B1
	for <FreeBSD-gnats-submit@freebsd.org>; Sat, 23 Oct 1999 21:04:31 -0700 (PDT)
	(envelope-from arnold@skeeve.com)
Received: from anx58-193.dialup.emory.edu (arnold@anx58-193.dialup.emory.edu [170.140.251.193])
	by moe.cc.emory.edu (8.8.8/8.8.8) with SMTP id AAA06154;
	Sun, 24 Oct 1999 00:04:09 -0400 (EDT)
Message-Id: <199910240404.AAA06154@moe.cc.emory.edu>
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

>Number:         14491
>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:   Sat Oct 23 21:10:01 PDT 1999
>Closed-Date:    Sun Nov 7 13:54:14 PST 1999
>Last-Modified:  Wed Oct 26 06:03:42 GMT 2005
>Originator:     
>Release:        
>Organization:
>Environment:
>Description:
 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
 
 
>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:14 PST 1999 
State-Changed-Why:  
Followup to gnu/13921. 
>Unformatted:
