Subject: lib/33841: getopt_long results in core dump
To: None <lib-bug-people@netbsd.org, gnats-admin@netbsd.org,>
From: None <cheusov@tut.by>
List: netbsd-bugs
Date: 06/27/2006 21:30:00
>Number:         33841
>Category:       lib
>Synopsis:       getopt_long is buggy and results in core dump
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    lib-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Jun 27 21:30:00 +0000 2006
>Originator:     cheusov@tut.by
>Release:        NetBSD 3.0_STABLE
>Organization:
Best regards, Aleksey Cheusov.
>Environment:
System: NetBSD chen.chizhovka.net 3.0_STABLE NetBSD 3.0_STABLE (GENERIC) #2: Sun Mar 12 12:49:58 GMT 2006 cheusov@chen:/usr/src/sys/arch/i386/compile/GENERIC i386
Architecture: i386
Machine: i386
>Description:
See How-To-Repeat section
>How-To-Repeat:
0 #cat main.c
#include <getopt.h>
#include <stdio.h>

int main (int argc, char **argv)
{
        int c;

        struct option longopts [] = {
                {"foo", no_argument, 0, 'f'},
        };

        c = getopt_long (argc, argv, "f", longopts, NULL);
        printf ("c=%d\n", c);

        return 0;
}
0 #g++ -o main main.c
0 #./main -f
c=102
0 #./main --foo
c=102
0 #./main -b
main: unknown option -- b
c=63
0 #./main --bar
Segmentation fault (core dumped)
139 #

>Fix:

Unknown