shared/opts-parser: Fix crash when no options were given to the parser

When passing just a space, the number of input options becomes 0. In
this case, calling `bmalloc` should be avoided.
This commit is contained in:
Norihiro Kamae 2024-10-09 00:33:47 +09:00 committed by Ryan Foster
parent b082e1be33
commit 03d9fee46e

View File

@ -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));