Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!rutgers!sri-spam!mordor!lll-tis!elxsi!marduk!gww From: gww@marduk.UUCP (Gary Winiger) Newsgroups: comp.bugs.4bsd Subject: Getopt(3) doesn't return '?' when opterr == 0 and an illegal option is encountered +Fix Message-ID: <520@elxsi.UUCP> Date: Fri, 4-Sep-87 18:14:52 EDT Article-I.D.: elxsi.520 Posted: Fri Sep 4 18:14:52 1987 Date-Received: Sat, 5-Sep-87 21:26:35 EDT Sender: nobody@elxsi.UUCP Reply-To: gww@marduk.UUCP (Gary Winiger) Organization: ELXSI Super Computers, San Jose Lines: 71 Subject: Getopt(3) does not return '?' when opterr == 0 and an illegal option is encountered +Fix Index: libc/compat-sys5/getopt.c 4.3BSD +Fix Description: Getopt(3) should return '?' when either an illegal option or an option requiring an argument without on is encountered. Instead, it gets a segmentation violation on systems which do not permit dereferencing of null pointers. Repeat-By: Write a program which sets opterr to zero (0). Call that program with an illegal option. Fix: The marco ``tell'' should always cause ``return(BADCH)'' to be executed, regardless of printing a diagnostic message. The attached code solves this problem at Elxsi. Gary.. {ucbvax!sun,lll-lcc!lll-tis,amdahl!altos86,bridge2}!elxsi!gww --------- cut --------- snip --------- :.,$w diff ------------- *** /tmp/,RCSt1000299 Fri Jun 26 11:05:41 1987 --- getopt.c Fri Jun 26 11:05:26 1987 *************** *** 1,5 **** --- 1,9 ---- /* * $Log: getopt.c,v $ + * Revision 1.2 87/06/26 11:04:53 gww + * Return '?' when opterr == 0 and illegal option, or option requires an + * argument is encountered. + * * Revision 1.1 87/01/07 18:25:01 gww * Initial revision * *************** *** 11,17 **** */ #if defined(LIBC_SCCS) && !defined(lint) ! static char *ERcsId = "$Header: getopt.c,v 1.1 87/01/07 18:25:01 gww Exp $ ENIX BSD"; static char sccsid[] = "@(#)getopt.c 4.3 (Berkeley) 3/9/86"; #endif LIBC_SCCS and not lint --- 15,21 ---- */ #if defined(LIBC_SCCS) && !defined(lint) ! static char *ERcsId = "$Header: getopt.c,v 1.2 87/06/26 11:04:53 gww Exp $ ENIX BSD"; static char sccsid[] = "@(#)getopt.c 4.3 (Berkeley) 3/9/86"; #endif LIBC_SCCS and not lint *************** *** 27,34 **** #define BADCH (int)'?' #define EMSG "" ! #define tell(s) if (opterr) {fputs(*nargv,stderr);fputs(s,stderr); \ ! fputc(optopt,stderr);fputc('\n',stderr);return(BADCH);} getopt(nargc,nargv,ostr) int nargc; --- 31,38 ---- #define BADCH (int)'?' #define EMSG "" ! #define tell(s) {if (opterr) {fputs(*nargv,stderr);fputs(s,stderr); \ ! fputc(optopt,stderr);fputc('\n',stderr);}return(BADCH);} getopt(nargc,nargv,ostr) int nargc;