Skip to content

Commit b4102bf

Browse files
committed
Fix a bug in this code that made it do the wrong thing when an option
was a single '-'. Thanks to Andrew Kuchling.
1 parent b55e07f commit b4102bf

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

Python/getopt.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,10 @@ char optstring[];
6262
opt_ptr = &argv[optind++][1];
6363
}
6464

65-
if ((ptr = strchr(optstring, option = *opt_ptr++)) == NULL) {
65+
if ( (option = *opt_ptr++) == '\0')
66+
return -1;
67+
68+
if ((ptr = strchr(optstring, option)) == NULL) {
6669
if (opterr)
6770
fprintf(stderr, "Unknown option: -%c\n", option);
6871

0 commit comments

Comments
 (0)