From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS31976 209.132.180.0/23 X-Spam-Status: No, score=-3.1 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_GMAIL_RCVD, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 3CB2B1F461 for ; Fri, 5 Jul 2019 09:02:17 +0000 (UTC) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:mime-version:references:in-reply-to:from:date :message-id:subject:to:content-type; q=dns; s=default; b=H9WwRHs 1PxXUUuKjZV41ofOvPqPO2YHEuYh04QRclZC/4IOQMbpuD/PaKMwIaVkeQ9oSFe9 bhtLO5OTJHhOk8b0J/2ZgerYAemKozAcJnMGnxhRbQ5y4P88G1/YdfUp3otrRH5u fbAJLhNrAysogS2CBtqONb2QmKqeXJ0JkVCM= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:mime-version:references:in-reply-to:from:date :message-id:subject:to:content-type; s=default; bh=nVd1Yr1TUll9X Ag5FHxiHKFNLZ8=; b=qw0aAu1VzqqHHME1+KxXmaekIFM4eRSJBrREEOtHoQr9b TrRYx5UX/tjWffAG72lUwcPbv43jShausgZ/2fC41R4q3WT4d/CTwPd/9/JFH6ZY SZBpfBGn8Bm/8B5pJDEGKzUBacWX2fIWyVIsjy9GDM/szkbPYcRf6DcGLy0zHc= Received: (qmail 29526 invoked by alias); 5 Jul 2019 09:02:14 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Received: (qmail 29518 invoked by uid 89); 5 Jul 2019 09:02:14 -0000 Authentication-Results: sourceware.org; auth=none X-HELO: mail-io1-f66.google.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=av7v5SvqpSkQ8R8rK3tRcAqKP+P63wJ5D650y0JvTz8=; b=H85L1MpyeatKHh5LYzCyTPhp+xsbQ9Q8KbXKcWuGJiRA+irEsWledgxs9veS2caXwf 8wzJRT+sJGqCguXnOuMBnCIh7yZSHWZKrgeJuzc9LavrmO+IQD88fNvuJCvowFd1RXvb Cz6BwhcDpEHkGdt9Ev1A0/uuA7Bk2KMzqtn0Outrw8H6fGMYkTAUdXxVxugmqNyW4fwb FctJ9n6LxUA0z1oIDj8DiLkMPFDgfLkShwKtWCgLs72ixundPHVI9KVJU09ybtjGgpLV USYUalFOdukpirRl13wImkf3dJJBQXH8pTm3u4g7aXW0SrXuo4czbMTuxFx7xYoMOibY ppxw== MIME-Version: 1.0 References: <871s1bep2u.fsf@oldenburg2.str.redhat.com> In-Reply-To: From: Girish Joshi Date: Fri, 5 Jul 2019 05:01:59 -0400 Message-ID: Subject: Re: [PATCH] argp: argp.doc prints incorrectly when it starts with "\v" [BZ #19038] To: libc-alpha@sourceware.org Content-Type: text/plain; charset="UTF-8" Hello, Following is the patch with ChangeLog entry and a test case. Please let me know if any changes are needed in it. diff --git a/ChangeLog b/ChangeLog index fbe5cd8648..7b11db3127 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2019-07-04 Girish Joshi + + [BZ #19038] + * argp/argp-help.c: Added validation for printing pre and post doc. + * argp/tst-argp-help.c: Added testcase for docstring help/usage. + 2019-07-04 Andreas Schwab [BZ #24484] diff --git a/argp/Makefile b/argp/Makefile index d5c2d77658..073ea3049e 100644 --- a/argp/Makefile +++ b/argp/Makefile @@ -27,7 +27,7 @@ routines = $(addprefix argp-, ba fmtstream fs-xinl help parse pv \ pvh xinl eexst) tests = argp-test tst-argp1 bug-argp1 tst-argp2 bug-argp2 \ - tst-ldbl-argp + tst-ldbl-argp tst-argp-help CFLAGS-argp-help.c += $(uses-callbacks) -fexceptions CFLAGS-argp-parse.c += $(uses-callbacks) @@ -35,5 +35,6 @@ CFLAGS-argp-fmtstream.c += -fexceptions bug-argp1-ARGS = -- --help bug-argp2-ARGS = -- -d 111 --dstaddr 222 -p 333 --peer 444 +tst-argp-help-ARGS = -- --help include ../Rules diff --git a/argp/argp-help.c b/argp/argp-help.c index 3b1727c4aa..ee4d247824 100644 --- a/argp/argp-help.c +++ b/argp/argp-help.c @@ -1465,10 +1465,11 @@ argp_doc (const struct argp *argp, const struct argp_state *state, size_t inp_text_limit = 0; const char *doc = dgettext (argp->argp_domain, argp->doc); const struct argp_child *child = argp->children; + char *vt = 0; if (doc) { - char *vt = strchr (doc, '\v'); + vt = strchr (doc, '\v'); inp_text = post ? (vt ? vt + 1 : 0) : doc; inp_text_limit = (!post && vt) ? (vt - doc) : 0; } @@ -1498,8 +1499,11 @@ argp_doc (const struct argp *argp, const struct argp_state *state, if (text == inp_text && inp_text_limit) __argp_fmtstream_write (stream, inp_text, inp_text_limit); - else - __argp_fmtstream_puts (stream, text); + else{ + if((!vt && !child) || (text == inp_text && !first_only)){ + __argp_fmtstream_puts (stream, text); + } + } if (__argp_fmtstream_point (stream) > __argp_fmtstream_lmargin (stream)) __argp_fmtstream_putc (stream, '\n'); diff --git a/argp/tst-argp-help.c b/argp/tst-argp-help.c new file mode 100644 index 0000000000..7abb97f8df --- /dev/null +++ b/argp/tst-argp-help.c @@ -0,0 +1,39 @@ +/* Copyright (C) 2002-2019 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper , 2002. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include + +static int +do_test (void) +{ + + int argc = 2; + char *argv[3] = { (char *) "tst-argp-help", (char *) "--help", NULL }; + int remaining; + + static char doc[] = "\vthis is post_doc"; + static struct argp argp = {NULL, NULL, NULL, doc}; + + /* Parse and process arguments. */ + argp_parse(&argp, argc, argv, 0, &remaining, NULL); + + return 0; +} + +#define TEST_FUNCTION do_test () +#include "../test-skeleton.c" Thanks.