| Summary: | awk -v var=val coredump | ||
|---|---|---|---|
| Product: | Base System | Reporter: | Jin Guojun <jin> |
| Component: | gnu | Assignee: | Sheldon Hearn <sheldonh> |
| Status: | Closed FIXED | ||
| Severity: | Affects Only Me | CC: | arnold |
| Priority: | Normal | ||
| Version: | 3.3-RELEASE | ||
| Hardware: | Any | ||
| OS: | Any | ||
|
Description
Jin Guojun
1999-09-23 20:50:01 UTC
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.
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 State Changed From-To: open->analyzed gawk-3.0.6 imported on the vendor branch and merged onto HEAD. We'll merge it onto RELENG_4 soon. Responsible Changed From-To: freebsd-bugs->sheldonh My reminder. State Changed From-To: analyzed->closed gawk-3.0.6 was merged onto the RELENG_4 branch on 2000/08/15! |