[FFmpeg-devel] [PATCH 1/2] lavu/dict: fix set function when reuse existing key pointer

Michael Niedermayer michaelni at gmx.at
Thu Apr 2 01:09:59 CEST 2015


On Thu, Apr 02, 2015 at 12:37:34AM +0200, Lukasz Marek wrote:
> On 01.04.2015 04:33, Michael Niedermayer wrote:
> >On Wed, Apr 01, 2015 at 03:25:23AM +0200, Lukasz Marek wrote:
> >>Fixes following scenario:
> >>
> >>av_dict_set(&d, "key", "old", 0);
> >>AVDictionaryEentry *e = av_dict_get(d, "key", NULL, 0);
> >>av_dict_set(&d, e->key, "new", 0);
> >>
> >>Signed-off-by: Lukasz Marek <lukasz.m.luki2 at gmail.com>
> >>---
> >>  libavutil/dict.c | 18 ++++++++++++++++--
> >>  1 file changed, 16 insertions(+), 2 deletions(-)
> >>
> >>diff --git a/libavutil/dict.c b/libavutil/dict.c
> >>index 0d54c79..3163894 100644
> >>--- a/libavutil/dict.c
> >>+++ b/libavutil/dict.c
> >>@@ -72,6 +72,7 @@ int av_dict_set(AVDictionary **pm, const char *key, const char *value,
> >>      AVDictionary *m = *pm;
> >>      AVDictionaryEntry *tag = av_dict_get(m, key, NULL, flags);
> >>      char *oldval = NULL;
> >>+    int the_same_key = 0;
> >>
> >
> >does it work to av_strdup() both key and value if they need to be
> >strduped but at the top of the function and simplify the rest
> >accordingly ?
> 
> 
> something like attached?

yes, LGTM if tested with valgrind or similar

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Those who are too smart to engage in politics are punished by being
governed by those who are dumber. -- Plato 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20150402/1c7072c8/attachment.asc>


More information about the ffmpeg-devel mailing list