bug-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug-gawk] Changed FIELDWIDTHS separator behaviour for single field


From: Johannes Meixner
Subject: [bug-gawk] Changed FIELDWIDTHS separator behaviour for single field
Date: Thu, 28 Jul 2011 15:29:48 +0200 (CEST)
User-agent: Alpine 2.00 (LNX 1167 2008-08-23)


Hello,

a user reported to us (i.e. to SUSE) that since gawk-3.1.6
the FIELDWIDTHS separator can no longer be used to separate
a single field.

In gawk-3.1.5 it was:
-------------------------------------------------------------------------
# echo '1234567890' | awk 'BEGIN { FIELDWIDTHS="5" } { print $1 }'
12345
# echo '1234567890' | awk 'BEGIN { FIELDWIDTHS="5 5" } { print $1,$2 }'
12345 67890
-------------------------------------------------------------------------

Since gawk-3.1.6 it is:
-------------------------------------------------------------------------
# echo '1234567890' | awk 'BEGIN { FIELDWIDTHS="5" } { print $1 }'

# echo '1234567890' | awk 'BEGIN { FIELDWIDTHS="5 5" } { print $1,$2 }'
12345 67890
-------------------------------------------------------------------------

Because I did not find this changed behaviour mentioned
in the ChangeLog or NEWS file I assume this is a bug.

I like to propose the following patch (here for gawk-3.1.8 but it
seems in gawk-4.0.0 it is the same) to get back the old behaviour
(the too long "set_FIELDWIDTHS" line may be shown wrapped here):
-------------------------------------------------------------------------
--- field.c.orig        2010-01-28 17:06:55.000000000 +0100
+++ field.c     2011-07-28 14:43:13.000000000 +0200
@@ -978,10 +978,12 @@ set_FIELDWIDTHS()
        FIELDWIDTHS[0] = 0;
        for (i = 1; ; i++) {
                unsigned long int tmp;
-               if (i + 1 >= fw_alloc) {
+               if (i + 2 >= fw_alloc) {
                        fw_alloc *= 2;
erealloc(FIELDWIDTHS, int *, fw_alloc * sizeof(int), "set_FIELDWIDTHS");
                }
+               /* Initialize value to be end of list */
+               FIELDWIDTHS[i] = -1;
                /* Ensure that there is no leading `-' sign.  Otherwise,
                   strtoul would accept it and return a bogus result.  */
                while (is_blank(*scan)) {
@@ -1013,8 +1015,6 @@ set_FIELDWIDTHS()
                if (*scan == '\0')
                        break;
        }
-       if (i == 1)     /* empty string! */
-               i--;
        FIELDWIDTHS[i+1] = -1;

        update_PROCINFO("FS", "FIELDWIDTHS");
-------------------------------------------------------------------------


Kind Regards
Johannes Meixner
--
SUSE LINUX Products GmbH -- Maxfeldstrasse 5 -- 90409 Nuernberg -- Germany
HRB 16746 (AG Nuernberg) GF: Jeff Hawn, Jennifer Guild, Felix Imendoerffer



reply via email to

[Prev in Thread] Current Thread [Next in Thread]