[FFmpeg-devel] [PATCH 25/38] avfilter/avfilter: Honour the short options documentation

Andreas Rheinhardt andreas.rheinhardt at outlook.com
Sun Sep 12 13:53:23 EEST 2021


The documentation for filter arguments states that short options must
precede long options (i.e. those of the form key=value). Yet if
process_options() encounters arguments not abiding by this, it simply
treats short options after a long option as if it were parsing short
options for the first time. In particular, it overwrites options already
set earlier, possibly via other short options. This is not how it is
intended (as a comment in the code indicates).

This commit modifies the code to reject further shorthand options
after a long option has been encountered. After all, avfilter_init_str()
errors out upon unrecognized options, so it is intended to be picky.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
---
The while loop that is removed below is actually just an elaborate
"o = NULL", which av_opt_next() interprets as "start the iteration".

 libavfilter/avfilter.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
index cc499fd5ed..165ab1f44a 100644
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.c
@@ -814,6 +814,7 @@ static int process_options(AVFilterContext *ctx, AVDictionary **options,
     const AVOption *o = NULL;
     int ret;
     char *av_uninit(parsed_key), *av_uninit(value);
+    const AVClass *priv = ctx->filter->priv_class;
     const char *key;
     int offset= -1;
 
@@ -824,8 +825,7 @@ static int process_options(AVFilterContext *ctx, AVDictionary **options,
         const char *shorthand = NULL;
         int flags = AV_DICT_DONT_STRDUP_VAL;
 
-        o = av_opt_next(ctx->priv, o);
-        if (o) {
+        if (priv && (o = av_opt_next(ctx->priv, o))) {
             if (o->type == AV_OPT_TYPE_CONST || o->offset == offset)
                 continue;
             offset = o->offset;
@@ -848,7 +848,7 @@ static int process_options(AVFilterContext *ctx, AVDictionary **options,
         if (parsed_key) {
             key = parsed_key;
             flags |= AV_DICT_DONT_STRDUP_KEY;
-            while ((o = av_opt_next(ctx->priv, o))); /* discard all remaining shorthand */
+            priv = NULL; /* reject all remaining shorthand */
         } else {
             key = shorthand;
         }
-- 
2.30.2



More information about the ffmpeg-devel mailing list