From d72c86f95c9292c15e96a1f3fb8471ebb28aa6da Mon Sep 17 00:00:00 2001 From: Dudemanguy Date: Wed, 25 Oct 2023 13:33:59 -0500 Subject: [PATCH] m_option: remove all matches when using -remove When using -remove with list options, it previously only removed the first match. Technically, it is possible for there to be more than entry with the same name. They should all be removed. key/value lists specifically only allow unique keys so we don't need to do anything there. --- options/m_option.c | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/options/m_option.c b/options/m_option.c index 458d38bafc..cf1ea53948 100644 --- a/options/m_option.c +++ b/options/m_option.c @@ -1456,14 +1456,20 @@ static int parse_str_list_impl(struct mp_log *log, const m_option_t *opt, if (op == OP_TOGGLE || op == OP_REMOVE) { if (dst) { char **list = VAL(dst); - int index = find_list_bstr(list, param); - if (index >= 0) { - char *old = list[index]; - for (int n = index; list[n]; n++) - list[n] = list[n + 1]; - talloc_free(old); + bool found = false; + int index = 0; + do { + index = find_list_bstr(list, param); + if (index >= 0) { + found = true; + char *old = list[index]; + for (int n = index; list[n]; n++) + list[n] = list[n + 1]; + talloc_free(old); + } + } while (index >= 0); + if (found) return 1; - } } if (op == OP_REMOVE) return 1; // ignore if not found @@ -3344,12 +3350,15 @@ static int parse_obj_settings_del(struct mp_log *log, struct bstr opt_name, if (bstr_startswith0(s, ":")) return 0; if (dst) { - int label_index = obj_settings_list_find_by_label(VAL(dst), label); - if (label_index >= 0) { - mark_del[label_index] = true; - } else { - mp_warn(log, "Option %.*s: item label @%.*s not found.\n", - BSTR_P(opt_name), BSTR_P(label)); + int label_index = 0; + while (label_index >= 0) { + label_index = obj_settings_list_find_by_label(VAL(dst), label); + if (label_index >= 0) { + mark_del[label_index] = true; + } else { + mp_warn(log, "Option %.*s: item label @%.*s not found.\n", + BSTR_P(opt_name), BSTR_P(label)); + } } } *param = s;