[FFmpeg-devel] [PATCH]lavc/decode: Initialize a return value on get_format() error

Carl Eugen Hoyos ceffmpeg at gmail.com
Mon Dec 10 02:51:01 EET 2018


2018-12-09 18:54 GMT+01:00, Mark Thompson <sw at jkqxz.net>:
> On 06/12/2018 22:27, Carl Eugen Hoyos wrote:
>> Hi!
>>
>> Attached patch silences a clang warning, please comment.
>>
>> Carl Eugen
>>
>>
>> From 3b5fc2473235410920ca89c7d84654e2ce8fb29d Mon Sep 17 00:00:00 2001
>> From: Carl Eugen Hoyos <ceffmpeg at gmail.com>
>> Date: Thu, 6 Dec 2018 23:17:13 +0100
>> Subject: [PATCH] lavc/decode: Initialize return value for get_format()
>>  failure.
>>
>> Silences a warning:
>> libavcodec/decode.c:1378:13: warning: variable 'ret' is used uninitialized
>> whenever 'if' condition is true
>> ---
>>  libavcodec/decode.c |    1 +
>>  1 file changed, 1 insertion(+)
>>
>> diff --git a/libavcodec/decode.c b/libavcodec/decode.c
>> index c89c77c..a32ff2f 100644
>> --- a/libavcodec/decode.c
>> +++ b/libavcodec/decode.c
>> @@ -1378,6 +1378,7 @@ int ff_get_format(AVCodecContext *avctx, const enum
>> AVPixelFormat *fmt)
>>          if (i == n) {
>>              av_log(avctx, AV_LOG_ERROR, "Invalid return from
>> get_format(): "
>>                     "%s not in possible list.\n", desc->name);
>> +            ret = AV_PIX_FMT_NONE;
>>              break;
>>          }
>>
>> --
>> 1.7.10.4
>>
>
> LGTM.

Patch applied.

> I think I'd also be happy with an assert there that this doesn't happen -
> it's difficult to argue that the user returning a nonsensical value from
> get_format is anything other than undefined behaviour.

I am generally a fan of asserts but I don't think this would be right.

Thank you, Carl Eugen


More information about the ffmpeg-devel mailing list