[FFmpeg-devel] [PATCH 2/4] parse_key_value_pair: Support keys without values with AV_DICT_ALLOW_NULLVAL

Michael Niedermayer michaelni at gmx.at
Sat Jul 20 18:55:03 CEST 2013


Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
---
 libavutil/dict.c |   12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/libavutil/dict.c b/libavutil/dict.c
index f965492..40434b6 100644
--- a/libavutil/dict.c
+++ b/libavutil/dict.c
@@ -116,6 +116,7 @@ static int parse_key_value_pair(AVDictionary **pm, const char **buf,
                                 const char *key_val_sep, const char *pairs_sep,
                                 int flags)
 {
+    char *buf2= *buf;
     char *key = av_get_token(buf, key_val_sep);
     char *val = NULL;
     int ret;
@@ -125,8 +126,19 @@ static int parse_key_value_pair(AVDictionary **pm, const char **buf,
         val = av_get_token(buf, pairs_sep);
     }
 
+    if (flags & AV_DICT_ALLOW_NULLVAL) {
+        char *key2 = av_get_token(&buf2, pairs_sep);
+        if (!key || (key2 && strlen(key2) < strlen(key))) {
+            FFSWAP(char *, *buf, buf2);
+            FFSWAP(char *, key, key2);
+            av_freep(&val);
+        }
+        av_freep(&key2);
+    }
     if (key && *key && val && *val)
         ret = av_dict_set(pm, key, val, flags);
+    else if (key && *key && !val && (flags & AV_DICT_ALLOW_NULLVAL))
+        ret = av_dict_set(pm, key, val, flags);
     else
         ret = AVERROR(EINVAL);
 
-- 
1.7.9.5



More information about the ffmpeg-devel mailing list