bug-gawk
[Top][All Lists]
Advanced

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

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


From: Aharon Robbins
Subject: Re: [bug-gawk] Changed FIELDWIDTHS separator behaviour for single field
Date: Wed, 10 Aug 2011 22:13:55 +0300
User-agent: Heirloom mailx 12.4 7/29/08

Hi. Thanks for this report and patch. I have integrated the patch
into the gawk-4.0-stable branch and pushed the change to the Savannah
repo.

FWIW, I see the "correct" behavior in 3.1.4, and wrong behavior in
3.1.5 and forward.  Just goes to show how much this feature is used... :-(

Thanks!

Arnold

> Date: Thu, 28 Jul 2011 15:29:48 +0200 (CEST)
> From: Johannes Meixner <address@hidden>
> To: address@hidden
> Subject: [bug-gawk] Changed FIELDWIDTHS separator behaviour for single field
>
> 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]