bug-gawk
[Top][All Lists]
Advanced

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

Re: fix getopt.awk first long option parsing


From: arnold
Subject: Re: fix getopt.awk first long option parsing
Date: Thu, 02 Feb 2023 09:59:05 -0700
User-agent: Heirloom mailx 12.5 7/5/10

Hi.

Sorry for the delay. I have applied your patch. It will be
in Git shortly.

Thanks!

Arnold

Przemek Kitszel <przemyslaw.kitszel@intel.com> wrote:

> Configuration Information [Automatically generated, do not change]:
> Machine: x86_64
> OS: linux-gnu
> Compiler: gcc
> Compilation CFLAGS: -g -O2 -DNDEBUG
> uname output: Linux pkitszel-desk 6.0.9-100.fc35.x86_64 #1 SMP 
> PREEMPT_DYNAMIC Wed Nov 16 17:25:52 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
> Machine Type: x86_64-pc-linux-gnu
>
> Gawk Version: 5.2.1
>
> Attestation 1:
>       I have read 
> https://www.gnu.org/software/gawk/manual/html_node/Bugs.html.
>       Yes
>
> Attestation 2:
>       I have not modified the sources before building gawk.
>       True
>
> Description:
>       First long option of getopt() distributed with gawk fails to accept 
> value.
>
> Repeat-By:
>       Following program demonstrates the problem:
>               #!/usr/bin/gawk -f
>               @include "getopt"
>               BEGIN {
>                       while ((opt = getopt(ARGC, ARGV, "", "iface:")) != -1) {
>                               print opt, Optarg
>                       }
>               }
>       Executed like: prog.awk -- --iface=eth0
>       Should print "iface eth0", but prints only "iface ".
>
> Fix:
>       Apply my patch, either from Github Gist:
>       https://gist.github.com/pkitszel/4027229617708b0a06ae8a6137a015a5
>       or attached at the end below.
> Thanks,
> Przemek
>
> First longopt option should have params properly assigned by now.
> The bug was that old code assumed index offset of 1 for ",", which
> is not necessairly at the very begining.
> ---
>  getopt.awk | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/getopt.awk b/getopt.awk
> index 69944f3fe724..1cf205bae863 100644
> --- a/getopt.awk
> +++ b/getopt.awk
> @@ -78,7 +78,7 @@ function getopt(argc, argv, options, longopts,    thisopt, 
> i, j)
>              Optind++
>              return "?"
>          }
> -        if (substr(longopts, i+1+length(thisopt), 1) == ":") {
> +        if (substr(longopts, i-1+RLENGTH, 1) == ":") {
>              if (j > 0)
>                  Optarg = substr(argv[Optind], j + 1)
>              else
> -- 
> 2.38.1



reply via email to

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