diff mbox series

[FFmpeg-devel,2/7] avcodec/av1dec: initialize ret in av1_receive_frame_internal()

Message ID 20240502004150.3627661-2-michael@niedermayer.cc
State New
Headers show
Series [FFmpeg-devel,1/7] avcodec/av1dec: bit_depth cannot be another values than 8, 10, 12 | expand

Commit Message

Michael Niedermayer May 2, 2024, 12:41 a.m. UTC
Fixes: CID1596605 Uninitialized scalar variable

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavcodec/av1dec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

James Almer May 2, 2024, 12:55 a.m. UTC | #1
On 5/1/2024 9:41 PM, Michael Niedermayer wrote:
> Fixes: CID1596605 Uninitialized scalar variable
> 
> Sponsored-by: Sovereign Tech Fund
> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
>   libavcodec/av1dec.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/libavcodec/av1dec.c b/libavcodec/av1dec.c
> index 4f9222cca27..93ab04eb378 100644
> --- a/libavcodec/av1dec.c
> +++ b/libavcodec/av1dec.c
> @@ -1262,7 +1262,7 @@ static int av1_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame)
>   {
>       AV1DecContext *s = avctx->priv_data;
>       AV1RawTileGroup *raw_tile_group = NULL;
> -    int i = 0, ret;
> +    int i = 0, ret = 0;
>   
>       for (i = s->nb_unit; i < s->current_obu.nb_units; i++) {
>           CodedBitstreamUnit *unit = &s->current_obu.units[i];

Should be ok. Alternatively, we could set ret to AVERROR_BUG here and to 
0 in the places where it's missing (and that triggered coverity).
Andreas Rheinhardt May 2, 2024, 7:12 a.m. UTC | #2
Michael Niedermayer:
> Fixes: CID1596605 Uninitialized scalar variable
> 
> Sponsored-by: Sovereign Tech Fund
> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
>  libavcodec/av1dec.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/libavcodec/av1dec.c b/libavcodec/av1dec.c
> index 4f9222cca27..93ab04eb378 100644
> --- a/libavcodec/av1dec.c
> +++ b/libavcodec/av1dec.c
> @@ -1262,7 +1262,7 @@ static int av1_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame)
>  {
>      AV1DecContext *s = avctx->priv_data;
>      AV1RawTileGroup *raw_tile_group = NULL;
> -    int i = 0, ret;
> +    int i = 0, ret = 0;
>  
>      for (i = s->nb_unit; i < s->current_obu.nb_units; i++) {
>          CodedBitstreamUnit *unit = &s->current_obu.units[i];

A better approach is to actually initialize ret before every goto end in
order to ensure that only the actually desired ret is returned and not
some earlier value.

- Andreas
Michael Niedermayer May 2, 2024, 9:29 p.m. UTC | #3
On Thu, May 02, 2024 at 09:12:36AM +0200, Andreas Rheinhardt wrote:
> Michael Niedermayer:
> > Fixes: CID1596605 Uninitialized scalar variable
> > 
> > Sponsored-by: Sovereign Tech Fund
> > Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> > ---
> >  libavcodec/av1dec.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/libavcodec/av1dec.c b/libavcodec/av1dec.c
> > index 4f9222cca27..93ab04eb378 100644
> > --- a/libavcodec/av1dec.c
> > +++ b/libavcodec/av1dec.c
> > @@ -1262,7 +1262,7 @@ static int av1_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame)
> >  {
> >      AV1DecContext *s = avctx->priv_data;
> >      AV1RawTileGroup *raw_tile_group = NULL;
> > -    int i = 0, ret;
> > +    int i = 0, ret = 0;
> >  
> >      for (i = s->nb_unit; i < s->current_obu.nb_units; i++) {
> >          CodedBitstreamUnit *unit = &s->current_obu.units[i];
> 
> A better approach is to actually initialize ret before every goto end in
> order to ensure that only the actually desired ret is returned and not
> some earlier value.

ok, will apply with ret = 0 before the 2 goto end lacking it that i see

thx

[...]
Andreas Rheinhardt May 2, 2024, 9:34 p.m. UTC | #4
Michael Niedermayer:
> On Thu, May 02, 2024 at 09:12:36AM +0200, Andreas Rheinhardt wrote:
>> Michael Niedermayer:
>>> Fixes: CID1596605 Uninitialized scalar variable
>>>
>>> Sponsored-by: Sovereign Tech Fund
>>> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
>>> ---
>>>  libavcodec/av1dec.c | 2 +-
>>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/libavcodec/av1dec.c b/libavcodec/av1dec.c
>>> index 4f9222cca27..93ab04eb378 100644
>>> --- a/libavcodec/av1dec.c
>>> +++ b/libavcodec/av1dec.c
>>> @@ -1262,7 +1262,7 @@ static int av1_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame)
>>>  {
>>>      AV1DecContext *s = avctx->priv_data;
>>>      AV1RawTileGroup *raw_tile_group = NULL;
>>> -    int i = 0, ret;
>>> +    int i = 0, ret = 0;
>>>  
>>>      for (i = s->nb_unit; i < s->current_obu.nb_units; i++) {
>>>          CodedBitstreamUnit *unit = &s->current_obu.units[i];
>>
>> A better approach is to actually initialize ret before every goto end in
>> order to ensure that only the actually desired ret is returned and not
>> some earlier value.
> 
> ok, will apply with ret = 0 before the 2 goto end lacking it that i see
> 

I already sent a patch for this.

- Andreas
Michael Niedermayer May 2, 2024, 9:41 p.m. UTC | #5
On Thu, May 02, 2024 at 11:34:48PM +0200, Andreas Rheinhardt wrote:
> Michael Niedermayer:
> > On Thu, May 02, 2024 at 09:12:36AM +0200, Andreas Rheinhardt wrote:
> >> Michael Niedermayer:
> >>> Fixes: CID1596605 Uninitialized scalar variable
> >>>
> >>> Sponsored-by: Sovereign Tech Fund
> >>> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> >>> ---
> >>>  libavcodec/av1dec.c | 2 +-
> >>>  1 file changed, 1 insertion(+), 1 deletion(-)
> >>>
> >>> diff --git a/libavcodec/av1dec.c b/libavcodec/av1dec.c
> >>> index 4f9222cca27..93ab04eb378 100644
> >>> --- a/libavcodec/av1dec.c
> >>> +++ b/libavcodec/av1dec.c
> >>> @@ -1262,7 +1262,7 @@ static int av1_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame)
> >>>  {
> >>>      AV1DecContext *s = avctx->priv_data;
> >>>      AV1RawTileGroup *raw_tile_group = NULL;
> >>> -    int i = 0, ret;
> >>> +    int i = 0, ret = 0;
> >>>  
> >>>      for (i = s->nb_unit; i < s->current_obu.nb_units; i++) {
> >>>          CodedBitstreamUnit *unit = &s->current_obu.units[i];
> >>
> >> A better approach is to actually initialize ret before every goto end in
> >> order to ensure that only the actually desired ret is returned and not
> >> some earlier value.
> > 
> > ok, will apply with ret = 0 before the 2 goto end lacking it that i see
> > 
> 
> I already sent a patch for this.

ok, ill drop mine then

thx

[...]
diff mbox series

Patch

diff --git a/libavcodec/av1dec.c b/libavcodec/av1dec.c
index 4f9222cca27..93ab04eb378 100644
--- a/libavcodec/av1dec.c
+++ b/libavcodec/av1dec.c
@@ -1262,7 +1262,7 @@  static int av1_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame)
 {
     AV1DecContext *s = avctx->priv_data;
     AV1RawTileGroup *raw_tile_group = NULL;
-    int i = 0, ret;
+    int i = 0, ret = 0;
 
     for (i = s->nb_unit; i < s->current_obu.nb_units; i++) {
         CodedBitstreamUnit *unit = &s->current_obu.units[i];