public inbox for glibc-bugs@sourceware.org help / color / mirror / Atom feed
From: "alain.bonnefoy@rieter.com" <sourceware-bugzilla@sources.redhat.com> To: glibc-bugs@sources.redhat.com Subject: [Bug libc/569] New: getopt_long option parsing Date: Tue, 23 Nov 2004 07:12:00 -0000 [thread overview] Message-ID: <20041123071225.569.alain.bonnefoy@rieter.com> (raw) According to what I saw in the getopt_long source code, the optional argument parsing test is: if (o->has_arg>0) { if (*max=='=') optarg=max+1; else { optarg=argv[optind+1]; ++optind; // These two 'if' code blocks fix a bug about optional argument missing. // More, I added two additional test with (optarg[0] == '-') as I consider that dash // specify an option only if it's followed by a character different from space or end of string if ((o->has_arg==1) && (!optarg || ((optarg[0] == '-') && (optarg[1] != ' ') && (optarg[1] != '\0')))) { /* no mandatory argument there */ if (*optstring==':') return ':'; write(2,"argument required: `",20); write(2,arg,max-arg); write(2,"'.\n",3); return '?'; } if ((o->has_arg==2) && (!optarg || ((optarg[0] == '-') && (optarg[1] != ' ') && (optarg[1] != '\0')))) { /* no optional argument there */ optarg = NULL; if (!o->flag) return o->val; return 0; } } } The problem of this code is that it doesn't allow to specify negative values as optional parameters such as: # my_cmd --setmin -100 --setmax 100 What I propose is to add an additional test to accept a dash character as optional argument if it is followed by a digit: if (o->has_arg>0) { if (*max=='=') optarg=max+1; else { optarg=argv[optind+1]; ++optind; // These two 'if' code blocks fix a bug about optional argument missing. // More, I added two additional test with (optarg[0] == '-') as I consider that dash // specify an option only if it's followed by a character different from space or end of string AND it's not a digit like a negative value if ((o->has_arg==1) && (!optarg || ((optarg[0] == '-') && (!isdigit(optarg[1])) && (optarg[1] != ' ') && (optarg[1] != '\0')))) { /* no mandatory argument there */ if (*optstring==':') return ':'; write(2,"argument required: `",20); write(2,arg,max-arg); write(2,"'.\n",3); return '?'; } if ((o->has_arg==2) && (!optarg || ((optarg[0] == '-') && (!isdigit(optarg[1])) && (optarg[1] != ' ') && (optarg[1] != '\0')))) { /* no optional argument there */ optarg = NULL; if (!o->flag) return o->val; return 0; } } } Kind regards, A.Bonnefoy -- Summary: getopt_long option parsing Product: glibc Version: unspecified Status: NEW Severity: normal Priority: P2 Component: libc AssignedTo: gotom at debian dot or dot jp ReportedBy: alain dot bonnefoy at rieter dot com CC: glibc-bugs at sources dot redhat dot com GCC build triplet: any GCC host triplet: any GCC target triplet: any http://sources.redhat.com/bugzilla/show_bug.cgi?id=569 ------- You are receiving this mail because: ------- You are on the CC list for the bug, or are watching someone who is.
next reply other threads:[~2004-11-23 7:12 UTC|newest] Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top 2004-11-23 7:12 alain.bonnefoy@rieter.com [this message] 2004-11-23 7:15 ` [Bug libc/569] " alain.bonnefoy@rieter.com 2004-11-23 10:50 ` schwab@suse.de 2004-11-25 12:58 ` alain.bonnefoy@rieter.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=20041123071225.569.alain.bonnefoy@rieter.com \ --to=sourceware-bugzilla@sources.redhat.com \ --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: linkBe 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).