This is the mail archive of the libc-alpha@sourceware.cygnus.com 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]

[mukesh_gupta@mil.emc.com] libc/1413: Incompatibility b/w getopt() with '+' as the first character in the optstring and getopt() without '+' as the first character in optstring....



Do we support this kind of usage at all?  '+' should be given always -
or never.  What do you think?

Andreas



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
***************************



-- 
 Andreas Jaeger
  SuSE Labs aj@suse.de
   private aj@arthur.rhein-neckar.de

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