[FFmpeg-devel] [PATCH 3/3] avutil/dict: Avoid check whose result is known in advance

Paul B Mahol onemda at gmail.com
Tue Sep 13 22:51:23 EEST 2022


On 9/13/22, Andreas Rheinhardt <andreas.rheinhardt at outlook.com> wrote:
> We know that an AVDictionary is not empty if we have just added
> an entry to it, so only check for it being empty on the branch
> that does not do so.
>
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
> ---
>  libavutil/dict.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
>

LGTM

> diff --git a/libavutil/dict.c b/libavutil/dict.c
> index 1968063b0b..4bba041d0a 100644
> --- a/libavutil/dict.c
> +++ b/libavutil/dict.c
> @@ -123,12 +123,12 @@ int av_dict_set(AVDictionary **pm, const char *key,
> const char *value,
>          m->elems[m->count].value = copy_value;
>          m->count++;
>      } else {
> +        if (!m->count) {
> +            av_freep(&m->elems);
> +            av_freep(pm);
> +        }
>          av_freep(&copy_key);
>      }
> -    if (!m->count) {
> -        av_freep(&m->elems);
> -        av_freep(pm);
> -    }
>
>      return 0;
>
> --
> 2.34.1
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request at ffmpeg.org with subject "unsubscribe".
>


More information about the ffmpeg-devel mailing list