Skip to content

Commit

Permalink
shared/opts-parser: Fix crash when no options were given to the parser
Browse files Browse the repository at this point in the history
When passing just a space, the number of input options becomes 0. In
this case, calling `bmalloc` should be avoided.
  • Loading branch information
norihiro authored and RytoEX committed Oct 8, 2024
1 parent b082e1b commit 03d9fee
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions shared/opts-parser/opts-parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ struct obs_options obs_parse_options(const char *options_string)
size_t input_option_count = 0;
for (char **input_word = input_words; *input_word; ++input_word)
input_option_count += 1;

if (!input_option_count) {
strlist_free(input_words);
goto failure;
}

char **ignored_words = bmalloc(input_option_count * sizeof(*ignored_words));
char **ignored_word = ignored_words;
struct obs_option *out_options = bmalloc(input_option_count * sizeof(*out_options));
Expand Down

0 comments on commit 03d9fee

Please sign in to comment.