diff Python/getopt.c @ 6364:f39bee3ff22b legacy-trunk

Fix a bug in this code that made it do the wrong thing when an option was a single '-'. Thanks to Andrew Kuchling.
author Guido van Rossum <guido@python.org>
date Tue, 30 Sep 1997 22:00:13 +0000
parents e8996884e8e1
children 4e15d175eed0
line wrap: on
line diff
--- a/Python/getopt.c	Tue Sep 30 21:59:27 1997 +0000
+++ b/Python/getopt.c	Tue Sep 30 22:00:13 1997 +0000
@@ -62,7 +62,10 @@
 		opt_ptr = &argv[optind++][1]; 
 	}
 
-	if ((ptr = strchr(optstring, option = *opt_ptr++)) == NULL) {
+	if ( (option = *opt_ptr++) == '\0')
+	  return -1;
+	
+	if ((ptr = strchr(optstring, option)) == NULL) {
 		if (opterr)
 			fprintf(stderr, "Unknown option: -%c\n", option);