summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--options/m_option.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/options/m_option.c b/options/m_option.c
index 7d95d93fb9..020bd371ce 100644
--- a/options/m_option.c
+++ b/options/m_option.c
@@ -743,13 +743,18 @@ static int apply_flag(const struct m_option *opt, int *val, bstr flag)
static const char *find_next_flag(const struct m_option *opt, int *val)
{
+ struct m_opt_choice_alternatives *best = NULL;
struct m_opt_choice_alternatives *alt;
for (alt = opt->priv; alt->name; alt++) {
if (alt->value && (alt->value & (*val)) == alt->value) {
- *val = *val & ~(unsigned)alt->value;
- return alt->name;
+ if (!best || av_popcount64(alt->value) > av_popcount64(best->value))
+ best = alt;
}
}
+ if (best) {
+ *val = *val & ~(unsigned)best->value;
+ return best->name;
+ }
*val = 0; // if there are still flags left, there's not much we can do
return NULL;
}