diff options
Diffstat (limited to 'libbb')
-rw-r--r-- | libbb/getopt32.c | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/libbb/getopt32.c b/libbb/getopt32.c index 9e53dfd08..51e030653 100644 --- a/libbb/getopt32.c +++ b/libbb/getopt32.c | |||
@@ -117,7 +117,7 @@ const char *opt_complementary | |||
117 | if w is given once, GNU ps sets the width to 132, | 117 | if w is given once, GNU ps sets the width to 132, |
118 | if w is given more than once, it is "unlimited" | 118 | if w is given more than once, it is "unlimited" |
119 | 119 | ||
120 | int w_counter = 0; | 120 | int w_counter = 0; // must be initialized! |
121 | opt_complementary = "ww"; | 121 | opt_complementary = "ww"; |
122 | getopt32(argv, "w", &w_counter); | 122 | getopt32(argv, "w", &w_counter); |
123 | if (w_counter) | 123 | if (w_counter) |
@@ -220,7 +220,7 @@ Special characters: | |||
220 | "x--x" Variation of the above, it means that -x option should occur | 220 | "x--x" Variation of the above, it means that -x option should occur |
221 | at most once. | 221 | at most once. |
222 | 222 | ||
223 | "a+:" A plus after a char in opt_complementary means that the parameter | 223 | "a+" A plus after a char in opt_complementary means that the parameter |
224 | for this option is a nonnegative integer. It will be processed | 224 | for this option is a nonnegative integer. It will be processed |
225 | with xatoi_u() - allowed range is 0..INT_MAX. | 225 | with xatoi_u() - allowed range is 0..INT_MAX. |
226 | 226 | ||
@@ -255,7 +255,7 @@ Special characters: | |||
255 | For example from "id" applet: | 255 | For example from "id" applet: |
256 | 256 | ||
257 | // Don't allow -n -r -rn -ug -rug -nug -rnug | 257 | // Don't allow -n -r -rn -ug -rug -nug -rnug |
258 | opt_complementary = "r?ug:n?ug:?u--g:g--u"; | 258 | opt_complementary = "r?ug:n?ug:u--g:g--u"; |
259 | flags = getopt32(argv, "rnug"); | 259 | flags = getopt32(argv, "rnug"); |
260 | 260 | ||
261 | This example allowed only: | 261 | This example allowed only: |
@@ -545,11 +545,14 @@ getopt32(char **argv, const char *applet_opts, ...) | |||
545 | if (on_off->counter) | 545 | if (on_off->counter) |
546 | (*(on_off->counter))++; | 546 | (*(on_off->counter))++; |
547 | if (on_off->param_type == PARAM_LIST) { | 547 | if (on_off->param_type == PARAM_LIST) { |
548 | llist_add_to_end((llist_t **)(on_off->optarg), optarg); | 548 | if (optarg) |
549 | llist_add_to_end((llist_t **)(on_off->optarg), optarg); | ||
549 | } else if (on_off->param_type == PARAM_INT) { | 550 | } else if (on_off->param_type == PARAM_INT) { |
550 | *(unsigned*)(on_off->optarg) = xatoi_u(optarg); | 551 | if (optarg) |
552 | *(unsigned*)(on_off->optarg) = xatoi_u(optarg); | ||
551 | } else if (on_off->optarg) { | 553 | } else if (on_off->optarg) { |
552 | *(char **)(on_off->optarg) = optarg; | 554 | if (optarg) |
555 | *(char **)(on_off->optarg) = optarg; | ||
553 | } | 556 | } |
554 | if (pargv != NULL) | 557 | if (pargv != NULL) |
555 | break; | 558 | break; |