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/14896] New: getopt_long: optind contains invalid index in very specific cases


http://sourceware.org/bugzilla/show_bug.cgi?id=14896

             Bug #: 14896
           Summary: getopt_long: optind contains invalid index in very
                    specific cases
           Product: glibc
           Version: 2.15
            Status: NEW
          Severity: normal
          Priority: P2
         Component: libc
        AssignedTo: unassigned@sourceware.org
        ReportedBy: miguel.a.guedes@gmail.com
                CC: drepper.fsp@gmail.com
    Classification: Unclassified


Created attachment 6765
  --> http://sourceware.org/bugzilla/attachment.cgi?id=6765
Test source file that reproduces the bug

This bug affects getopt_long.

In very specific circumstances, optind points to the wrong option when a long
option is not recognised or is invalid.

I've attached a simple test program that reproduces the bug.

Run it like so, ie:

$ gcc test.c -o test && ./test --add -a no_arg lone-value --this-is-long
option add
option a
invalid option: lone-value
non-option ARGV-elements: lone-value 

In the example above, getopt_long's internal optind should have skipped
`lone-value' and be pointing at the invalid option `this-is-long'.

Attached source file makes this much clearer.

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


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