diff mbox

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

Message ID CAB0OVGoXES+am4d9+U7+Tw_hz6nsTspYJGL+zot7g4=Etko7SA@mail.gmail.com
State Accepted
Headers show

Commit Message

Carl Eugen Hoyos Dec. 6, 2018, 10:27 p.m. UTC
Hi!

Attached patch silences a clang warning, please comment.

Carl Eugen

Comments

Mark Thompson Dec. 9, 2018, 5:54 p.m. UTC | #1
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@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.

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.

Thanks,

- Mark
Carl Eugen Hoyos Dec. 10, 2018, 12:51 a.m. UTC | #2
2018-12-09 18:54 GMT+01:00, Mark Thompson <sw@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@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
diff mbox

Patch

From 3b5fc2473235410920ca89c7d84654e2ce8fb29d Mon Sep 17 00:00:00 2001
From: Carl Eugen Hoyos <ceffmpeg@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