This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libc/11043] New: botched messages printed by getopt with W;


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]