From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4662 invoked by alias); 2 Dec 2009 18:08:47 -0000 Received: (qmail 4607 invoked by uid 48); 2 Dec 2009 18:08:30 -0000 Date: Wed, 02 Dec 2009 18:08:00 -0000 From: "ebb9 at byu dot net" To: glibc-bugs@sources.redhat.com Message-ID: <20091202180829.11043.ebb9@byu.net> Reply-To: sourceware-bugzilla@sourceware.org Subject: [Bug libc/11043] New: botched messages printed by getopt with W; X-Bugzilla-Reason: CC Mailing-List: contact glibc-bugs-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: glibc-bugs-owner@sourceware.org X-SW-Source: 2009-12/txt/msg00009.txt.bz2 When using getopt_long with "W;", the error messages are inconsistent, and in some cases, downright wrong. $cat foo.c #include #include #include 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.