bug-gnulib
[Top][All Lists]
Advanced

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

[PATCH] lib/argp-help.c: Corrected the default value and usage for inp_t


From: Girish Joshi
Subject: [PATCH] lib/argp-help.c: Corrected the default value and usage for inp_text_limit in argp_doc()
Date: Mon, 8 Feb 2021 00:47:15 +0530

Hello,
This is in the reference to bugzilla entry #19038[1] for glibc.
It was suggested to submit this patch on this mailing list as the argp
module is shared in gnulib.

The details for the bug and the patch are as follows.

Overview:
argp.doc prints incorrectly when it starts with '\v'.
In argp-help.c in the function argp_doc() variable inp_text_limit is reset to 0
if the doc string starts with '\v'. Which causes the whole doc string to be
printed in the case of pre documentation, because of initialization of inp_text
and inp_text_limit

    inp_text = post ? (vt ? vt + 1 : 0) : doc;
    inp_text_limit = (!post && vt) ? (vt - doc) : 0;

and the condition where the doc string is printed.

    if (text == inp_text && inp_text_limit)
      __argp_fmtstream_write (stream, inp_text, inp_text_limit);

So for the following code

    #include<argp.h>

    static char doc[] = "\vthis is post_doc";
    static struct argp argp = {NULL, NULL, NULL, doc};

    int main(int argc, char *args[]){
         argp_parse(&argp, argc, args, 0, 0, NULL);
    }

the output is

    $ argp-help --help
    Usage: argp-help [OPTION...]

    this is post_doc

      -?, --help                 Give this help list
          --usage                Give a short usage message

    this is post_doc

As mentioned in the bugzilla entry the first occurrence of
"this is post_doc" is erroneous as it is the pre doc and there is nothing
in the doc string in the predoc section.

Implementation:
Reset the value of inp_text_limit to -1 if the doc string starts with '\v'.
Modify the condition for printing the complete doc string with validation for
inp_text_limit variable which looks like.

    if (text == inp_text && inp_text_limit != -1)
      __argp_fmtstream_write (stream, inp_text, inp_text_limit);

after applying this patch we get the output as following

    $ argp-help --help
    Usage: argp-help [OPTION...]

      -?, --help                 Give this help list
          --usage                Give a short usage message

    this is post_doc

Could someone please review this patch?

Thanks.
Girish Joshi

[1]: https://sourceware.org/bugzilla/show_bug.cgi?id=19038

Attachment: 0001-lib-argp-help.c-Corrected-the-default-value-and-usag.patch
Description: Text Data


reply via email to

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