[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: FIELDWIDTHS broken in awk 3.1.5
From: |
Aharon Robbins |
Subject: |
Re: FIELDWIDTHS broken in awk 3.1.5 |
Date: |
Sat, 22 Sep 2007 22:30:00 +0200 |
Greetings. This got sorta buried in my inbox. Sorry.
> Date: Wed, 25 Jan 2006 20:01:18 -0700
> From: Glenn Zazulia <address@hidden>
> Subject: Re: FIELDWIDTHS broken in awk 3.1.5
> To: address@hidden
> Cc: address@hidden
>
> Aharon,
>
> I found your FIELDWIDTHS patch which fixes a problem that I also noticed
> with the 3.1.5 gawk release.
>
> I also noticed a related possible problem with FIELDWIDTHS in the gawk
> 3.1.5 release. In gawk 3.1.4 and earlier, the statement
>
> FIELDWIDTHS = ""
>
> used to work -- that is, it was executed without error and a subsequent
> "print FIELDWIDTHS" statement showed that any previous value was unset.
> Running that statement through gawk 3.1.5 produces the following fatal
> error:
>
> gawk: (FILENAME=- FNR=1) fatal: invalid FIELDWIDTHS value, near `'
>
> Now, one might question what that statement should do, and one might
> argue that instead of being a new bug, this might be a fix of previously
> improper behavior. I don't think so. Since the FIELDWIDTHS variable is
> a gawk extension and since the documentation doesn't state what the
> behavior should be in this case, it's difficult for me to argue one way
> or the other. However, this change in behavior in 3.1.5 breaks existing
> gawk scripts, which is a problem.
I have restored the previous behavior. I decided not to really think about
what the "correct" thing is, preferring just to not crash and to have things
work as they used to.
Attached is a diff of my current field.c against vanilla 3.1.5.
Thanks!
Arnold
--- ../gawk-3.1.5/field.c 2005-05-11 18:28:15.000000000 +0300
+++ field.c 2007-09-22 22:23:05.000000000 +0200
@@ -3,14 +3,14 @@
*/
/*
- * Copyright (C) 1986, 1988, 1989, 1991-2005 the Free Software Foundation, Inc.
+ * Copyright (C) 1986, 1988, 1989, 1991-2007 the Free Software Foundation, Inc.
*
* This file is part of GAWK, the GNU implementation of the
* AWK Programming Language.
*
* GAWK is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* GAWK is distributed in the hope that it will be useful,
@@ -166,6 +166,7 @@
cops = ops;
ops[0] = '\0';
for (i = 1; i <= NF; i++) {
+ free_wstr(fields_arr[i]);
tmp = fields_arr[i];
/* copy field */
if (tmp->stlen == 1)
@@ -212,6 +213,9 @@
n->stptr = cops;
unref(fields_arr[i]);
fields_arr[i] = n;
+#ifdef MBS_SUPPORT
+ assert((n->flags & WSTRCUR) == 0);
+#endif
}
cops += fields_arr[i]->stlen + ofslen;
}
@@ -897,7 +901,7 @@
char *end;
register int i;
static int fw_alloc = 4;
- static int warned = FALSE;
+ static short warned = FALSE;
extern unsigned long strtoul P((const char *, char **endptr, int base));
if (do_lint && ! warned) {
@@ -916,13 +920,13 @@
parse_field = fw_parse_field;
scan = force_string(FIELDWIDTHS_node->var_value)->stptr;
- end = scan + 1;
+
if (FIELDWIDTHS == NULL)
emalloc(FIELDWIDTHS, int *, fw_alloc * sizeof(int),
"set_FIELDWIDTHS");
FIELDWIDTHS[0] = 0;
for (i = 1; ; i++) {
unsigned long int tmp;
- if (i >= fw_alloc) {
+ if (i + 1 >= fw_alloc) {
fw_alloc *= 2;
erealloc(FIELDWIDTHS, int *, fw_alloc * sizeof(int),
"set_FIELDWIDTHS");
}
@@ -935,13 +939,16 @@
fatal(_("invalid FIELDWIDTHS value, near `%s'"),
scan);
+ if (*scan == '\0')
+ break;
+
/* Detect an invalid base-10 integer, a valid value that
is followed by something other than a blank or '\0',
or a value that is not in the range [1..INT_MAX]. */
errno = 0;
tmp = strtoul(scan, &end, 10);
if (errno != 0
- || !(*end == '\0' || is_blank(*end))
+ || (*end != '\0' && ! is_blank(*end))
|| !(0 < tmp && tmp <= INT_MAX))
fatal(_("invalid FIELDWIDTHS value, near `%s'"),
scan);
@@ -954,7 +961,9 @@
if (*scan == '\0')
break;
}
- FIELDWIDTHS[i] = -1;
+ if (i == 1) /* empty string! */
+ i--;
+ FIELDWIDTHS[i+1] = -1;
update_PROCINFO("FS", "FIELDWIDTHS");
}
@@ -1027,6 +1036,8 @@
lintwarn(_("null string for `FS' is a gawk extension"));
}
} else if (fs->stlen > 1) {
+ if (do_lint_old)
+ warning(_("old awk does not support regexps as value of
`FS'"));
parse_field = re_parse_field;
} else if (RS_is_null) {
/* we know that fs->stlen <= 1 */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: FIELDWIDTHS broken in awk 3.1.5,
Aharon Robbins <=