- Subject: libc/1413: Incompatibility b/w getopt() with '+' as the first character in the optstring and getopt() without '+' as the first character in optstring....
- From: mukesh_gupta at mil dot emc dot com
- Date: Wed Dec 29 21:00:55 1999
Topics:
libc/1413: Incompatibility b/w getopt() with '+' as the first character in the optstring and getopt() without '+' as the first character in optstring....
----------------------------------------------------------------------
Date: Tue, 26 Oct 1999 12:36:02 -0400
From: mukesh_gupta@mil.emc.com
To: bugs@gnu.org
Subject: libc/1413: Incompatibility b/w getopt() with '+' as the first character in the optstring and getopt() without '+' as the first character in optstring....
Message-Id: <199910261636.MAA28228@delysid.gnu.org>
>Number: 1413
>Category: libc
>Synopsis: Incompatibility b/w getopt() with '+' as the first character in the optstring and getopt() without '+' as the first character in optstring....
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: libc-gnats
>State: open
>Class: sw-bug
>Submitter-Id: unknown
>Arrival-Date: Tue Oct 26 12:40:02 EDT 1999
>Last-Modified:
>Originator: mukesh_gupta@mil.emc.com
>Organization:
net
>Release:
>Environment:
>Description:
If someone calls getopt() in a program for the first time without '+' as the
first character in the optstring, the next subsequent calls to getopt() with the
'+' as the first character in the optstring will not behave in a posixly correct
manner and the option processing doesn't stop at the first non-option argument.
The '+' as the first character in the optstring has no influence on
the output and it will behave as '+' character has not been specified.
This is not in accordance with the manpage which says:
If the first character of optstring
is `+', then option processing stops as soon as a non-option
argument is encountered.
>How-To-Repeat:
bug.c
#include <unistd.h>
#include <stdio.h>
void main(int argc, char **argv)
{
char *OptionSwitches = "abcd";
char *PlusOptionSwitches = "+abcd";
char c;
optind = 1;
c = getopt(argc, argv, OptionSwitches);
switch(c)
{
case 'a':
printf("\nOptind: %d",optind);
break;
case 'b':
printf("\nOptind: %d",optind);
break;
case 'c':
printf("\nOptind: %d",optind);
break;
case 'd':
printf("\nOptind: %d",optind);
break;
default:
printf("\nError");
break;
}
optind = 1;
while(EOF != (c = getopt(argc, argv, PlusOptionSwitches)) )
{
switch(c)
{
case 'a':
printf("\nOptind: %d",optind);
break;
case 'b':
printf("\nOptind: %d",optind);
break;
case 'c':
printf("\nOptind: %d",optind);
break;
case 'd':
printf("\nOptind: %d",optind);
break;
default:
printf("\nError");
break;
}
}
}
cc bug.c -o bug
bug -a -b -c mukesh -d
The output comes
- ------------------------
Optind: 2 (from the first getopt)
Optind: 2 (from the second getopt)
Optind: 3 (from the second getopt)
Optind: 4 (from the second getopt)
Optind: 6 (from the second getopt, but why???)
- -----------------
The second getopt() system call shouldn't parse after the first non-option,
i.e., mukesh.
This is precisely the output that makes me believe that it's is a bug...
>Fix:
>Audit-Trail:
>Unformatted:
------------------------------
End of forward4yB7yE Digest
***************************