public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "ebb9 at byu dot net" <sourceware-bugzilla@sourceware.org>
To: glibc-bugs@sources.redhat.com
Subject: [Bug libc/11043] New: botched messages printed by getopt with W;
Date: Wed, 02 Dec 2009 18:08:00 -0000	[thread overview]
Message-ID: <20091202180829.11043.ebb9@byu.net> (raw)

When using getopt_long with "W;", the error messages are inconsistent, and in
some cases, downright wrong.

$cat foo.c
#include <unistd.h>
#include <stdio.h>
#include <getopt.h>

static const struct option opts[] =
  {
    { "alpha",    no_argument,       NULL, 'a' },
    { "beta",     required_argument, NULL, 'b' },
    { "c1",       no_argument,       NULL, 'c' },
    { "c2",       no_argument,       NULL, 'c' },
    { NULL,       0,                 NULL, 0 }
  };

int
main (int argc, char **argv)
{
  int c = getopt_long (argc, argv, "W;", opts, NULL);
  if (c == -1)
    puts ("got -1");
  else
    printf ("got %c\n", c);
  return 0;
}
$ ./foo --al=
./foo: option `--al=' doesn't allow an argument
got ?
$ ./foo -W al=
./foo: option `-W alpha' doesn't allow an argument
got ?
$ ./foo -Wal=
./foo: option `-W alpha' doesn't allow an argument
got ?
$ ./foo --be
./foo: option `--be' requires an argument
got ?
$ ./foo -W be
./foo: option `be' requires an argument
got ?
$ ./foo -Wbe
./foo: option `-Wbe' requires an argument
got ?
$ ./foo2 -W c a
./foo2: option `-W a' is ambiguous
got ?
$ ./foo2 -W c
./foo2: option `-W (null)' is ambiguous
got ?
$ ./foo2 -Wc a
./foo2: option `-W a' is ambiguous
got ?

Notice how with -W, an extra argument prints the full text of the struct option
rather than what the user typed and prints a space after the -W whether or not
the user had a space; a missing argument prints just the argv slot containing
what the user typed but without the -W; and an ambiguous argument prints the
wrong argv slot altogether (although whether this particular example should have
been ambiguous in the first place is already the subject of 11041).

-- 
           Summary: botched messages printed by getopt with W;
           Product: glibc
           Version: 2.11
            Status: NEW
          Severity: normal
          Priority: P2
         Component: libc
        AssignedTo: drepper at redhat dot com
        ReportedBy: ebb9 at byu dot net
                CC: glibc-bugs at sources dot redhat dot com
 BugsThisDependsOn: 11041


http://sourceware.org/bugzilla/show_bug.cgi?id=11043

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


             reply	other threads:[~2009-12-02 18:08 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-12-02 18:08 ebb9 at byu dot net [this message]
2010-04-05  5:50 ` [Bug libc/11043] " drepper at redhat dot com
2010-04-08  0:18 ` drepper at redhat dot com

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20091202180829.11043.ebb9@byu.net \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=glibc-bugs@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).