diff mbox series

[FFmpeg-devel] avformat/hlsenc: compiler warning fix

Message ID 31922e5e-3045-0a6f-e090-d78eb745efd0@vivanet.hu
State New
Headers show
Series [FFmpeg-devel] avformat/hlsenc: compiler warning fix | expand

Checks

Context Check Description
andriy/ffmpeg-patchwork success Make fate finished

Commit Message

Bodecs Bela Jan. 20, 2020, 7:34 a.m. UTC
Dear All,

This patch corrects compiler warning about returning possibly uninitialized
variable in hls_write_header function.

please review this patch!

Thank you in advance.

Bela
From e7b3a680f13fd6113f3bf118803d9609d0fe8bda Mon Sep 17 00:00:00 2001
From: Bela Bodecs <bodecsb@vivanet.hu>
Date: Mon, 20 Jan 2020 08:31:38 +0100
Subject: [PATCH] avformat/hlsenc: compiler warning fix

Correcting compiler warning about returning possibly uninitialized
variable in hls_write_header function.


Signed-off-by: Bela Bodecs <bodecsb@vivanet.hu>
---
 libavformat/hlsenc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Andreas Rheinhardt Jan. 20, 2020, 7:46 a.m. UTC | #1
On Mon, Jan 20, 2020 at 8:35 AM Bodecs Bela <bodecsb@vivanet.hu> wrote:

> Dear All,
>
> This patch corrects compiler warning about returning possibly uninitialized
> variable in hls_write_header function.
>
> Which compiler warns about this?

Regarding the patch: It's probably better to explicitly return 0 at the end
of hls_write_header() (as well as dash_write_header()).

- Andreas
Bodecs Bela Jan. 20, 2020, 8:41 a.m. UTC | #2
2020.01.20. 8:46 keltezéssel, Andreas Rheinhardt írta:
> On Mon, Jan 20, 2020 at 8:35 AM Bodecs Bela <bodecsb@vivanet.hu> wrote:
>
>> Dear All,
>>
>> This patch corrects compiler warning about returning possibly uninitialized
>> variable in hls_write_header function.
>>
>> Which compiler warns about this?

libavformat/hlsenc.c: In function ‘hls_write_header’:
libavformat/hlsenc.c:2174: warning: ‘ret’ may be used uninitialized in 
this function


gcc version 4.4.7 20120313 (Red Hat 4.4.7-23) (GCC)


> Regarding the patch: It's probably better to explicitly return 0 at the end
> of hls_write_header() (as well as dash_write_header()).

I have no objection, but maybe in a separate patch?


>
> - Andreas
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
Carl Eugen Hoyos Jan. 20, 2020, 12:07 p.m. UTC | #3
Am Mo., 20. Jan. 2020 um 09:41 Uhr schrieb Bodecs Bela <bodecsb@vivanet.hu>:
>
>
> 2020.01.20. 8:46 keltezéssel, Andreas Rheinhardt írta:
> > On Mon, Jan 20, 2020 at 8:35 AM Bodecs Bela <bodecsb@vivanet.hu> wrote:
> >
> >> Dear All,
> >>
> >> This patch corrects compiler warning about returning possibly uninitialized
> >> variable in hls_write_header function.
> >>
> >> Which compiler warns about this?
>
> libavformat/hlsenc.c: In function ‘hls_write_header’:
> libavformat/hlsenc.c:2174: warning: ‘ret’ may be used uninitialized in
> this function

Looks like a false positive, does not warn with newer compilers.

Carl Eugen
Bodecs Bela Jan. 20, 2020, 12:18 p.m. UTC | #4
2020.01.20. 13:07 keltezéssel, Carl Eugen Hoyos írta:
> Am Mo., 20. Jan. 2020 um 09:41 Uhr schrieb Bodecs Bela <bodecsb@vivanet.hu>:
>>
>> 2020.01.20. 8:46 keltezéssel, Andreas Rheinhardt írta:
>>> On Mon, Jan 20, 2020 at 8:35 AM Bodecs Bela <bodecsb@vivanet.hu> wrote:
>>>
>>>> Dear All,
>>>>
>>>> This patch corrects compiler warning about returning possibly uninitialized
>>>> variable in hls_write_header function.
>>>>
>>>> Which compiler warns about this?
>> libavformat/hlsenc.c: In function ‘hls_write_header’:
>> libavformat/hlsenc.c:2174: warning: ‘ret’ may be used uninitialized in
>> this function
> Looks like a false positive, does not warn with newer compilers.

yes and no.

no, because if hls->nb_varstreams == 0, then for loop body never 
executes and so ret does not get any value.

yes, because there is no chance for hls->nb_varstreams to be zero.

so, I think setting ret to 0 at its declaration does not do any problem 
and logically right.

>
> Carl Eugen
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
Carl Eugen Hoyos Jan. 20, 2020, 12:46 p.m. UTC | #5
Am Mo., 20. Jan. 2020 um 13:18 Uhr schrieb Bodecs Bela <bodecsb@vivanet.hu>:
>
>
> 2020.01.20. 13:07 keltezéssel, Carl Eugen Hoyos írta:
> > Am Mo., 20. Jan. 2020 um 09:41 Uhr schrieb Bodecs Bela <bodecsb@vivanet.hu>:
> >>
> >> 2020.01.20. 8:46 keltezéssel, Andreas Rheinhardt írta:
> >>> On Mon, Jan 20, 2020 at 8:35 AM Bodecs Bela <bodecsb@vivanet.hu> wrote:
> >>>
> >>>> Dear All,
> >>>>
> >>>> This patch corrects compiler warning about returning possibly uninitialized
> >>>> variable in hls_write_header function.
> >>>>
> >>>> Which compiler warns about this?
> >> libavformat/hlsenc.c: In function ‘hls_write_header’:
> >> libavformat/hlsenc.c:2174: warning: ‘ret’ may be used uninitialized in
> >> this function
> > Looks like a false positive, does not warn with newer compilers.
>
> yes and no.
>
> no, because if hls->nb_varstreams == 0, then for loop body never
> executes and so ret does not get any value.
>
> yes, because there is no chance for hls->nb_varstreams to be zero.
>
> so, I think setting ret to 0 at its declaration does not do any problem
> and logically right.

No, update your compiler instead.

Carl Eugen
Bodecs Bela Jan. 20, 2020, 12:56 p.m. UTC | #6
2020.01.20. 13:46 keltezéssel, Carl Eugen Hoyos írta:
> Am Mo., 20. Jan. 2020 um 13:18 Uhr schrieb Bodecs Bela <bodecsb@vivanet.hu>:
>>
>> 2020.01.20. 13:07 keltezéssel, Carl Eugen Hoyos írta:
>>> Am Mo., 20. Jan. 2020 um 09:41 Uhr schrieb Bodecs Bela <bodecsb@vivanet.hu>:
>>>> 2020.01.20. 8:46 keltezéssel, Andreas Rheinhardt írta:
>>>>> On Mon, Jan 20, 2020 at 8:35 AM Bodecs Bela <bodecsb@vivanet.hu> wrote:
>>>>>
>>>>>> Dear All,
>>>>>>
>>>>>> This patch corrects compiler warning about returning possibly uninitialized
>>>>>> variable in hls_write_header function.
>>>>>>
>>>>>> Which compiler warns about this?
>>>> libavformat/hlsenc.c: In function ‘hls_write_header’:
>>>> libavformat/hlsenc.c:2174: warning: ‘ret’ may be used uninitialized in
>>>> this function
>>> Looks like a false positive, does not warn with newer compilers.
>> yes and no.
>>
>> no, because if hls->nb_varstreams == 0, then for loop body never
>> executes and so ret does not get any value.
>>
>> yes, because there is no chance for hls->nb_varstreams to be zero.
>>
>> so, I think setting ret to 0 at its declaration does not do any problem
>> and logically right.
> No, update your compiler instead.
which of my statements did your "No" reference?
>
> Carl Eugen
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
Carl Eugen Hoyos Jan. 20, 2020, 1:02 p.m. UTC | #7
Am Mo., 20. Jan. 2020 um 13:56 Uhr schrieb Bodecs Bela <bodecsb@vivanet.hu>:
>
>
> 2020.01.20. 13:46 keltezéssel, Carl Eugen Hoyos írta:
> > Am Mo., 20. Jan. 2020 um 13:18 Uhr schrieb Bodecs Bela <bodecsb@vivanet.hu>:
> >>
> >> 2020.01.20. 13:07 keltezéssel, Carl Eugen Hoyos írta:
> >>> Am Mo., 20. Jan. 2020 um 09:41 Uhr schrieb Bodecs Bela <bodecsb@vivanet.hu>:
> >>>> 2020.01.20. 8:46 keltezéssel, Andreas Rheinhardt írta:
> >>>>> On Mon, Jan 20, 2020 at 8:35 AM Bodecs Bela <bodecsb@vivanet.hu> wrote:
> >>>>>
> >>>>>> Dear All,
> >>>>>>
> >>>>>> This patch corrects compiler warning about returning possibly uninitialized
> >>>>>> variable in hls_write_header function.
> >>>>>>
> >>>>>> Which compiler warns about this?
> >>>> libavformat/hlsenc.c: In function ‘hls_write_header’:
> >>>> libavformat/hlsenc.c:2174: warning: ‘ret’ may be used uninitialized in
> >>>> this function
> >>> Looks like a false positive, does not warn with newer compilers.
> >> yes and no.
> >>
> >> no, because if hls->nb_varstreams == 0, then for loop body never
> >> executes and so ret does not get any value.
> >>
> >> yes, because there is no chance for hls->nb_varstreams to be zero.
> >>
> >> so, I think setting ret to 0 at its declaration does not do any problem
> >> and logically right.
> > No, update your compiler instead.
> which of my statements did your "No" reference?

Both.

Please cut your quotes, Carl Eugen
Bodecs Bela Jan. 20, 2020, 1:18 p.m. UTC | #8
2020.01.20. 14:02 keltezéssel, Carl Eugen Hoyos írta:
>
>>>>>>>> This patch corrects compiler warning about returning possibly uninitialized
>>>>>>>> variable in hls_write_header function.
>>>>>>>>
>>>>>>>> Which compiler warns about this?
>>>>>> libavformat/hlsenc.c: In function ‘hls_write_header’:
>>>>>> libavformat/hlsenc.c:2174: warning: ‘ret’ may be used uninitialized in
>>>>>> this function
>>>>> Looks like a false positive, does not warn with newer compilers.
>>>> yes and no.
>>>>
>>>> no, because if hls->nb_varstreams == 0, then for loop body never
>>>> executes and so ret does not get any value.
>>>>
>>>> yes, because there is no chance for hls->nb_varstreams to be zero.
>>>>
>>>> so, I think setting ret to 0 at its declaration does not do any problem
>>>> and logically right.
>>> No, update your compiler instead.
>> which of my statements did your "No" reference?
> Both.

Thank you for your help. Maybe due to my poor english, but I really do 
not see,

I really did  test with other compiler and really did not give warning 
any longer,

but it does not help that the ret varaiable remain uninitalized but may 
be returned.

As I know theoretically there is no default value of an int variable.

So why the warning did disappear?

>
> Please cut your quotes, Carl Eugen
ok
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
Carl Eugen Hoyos Jan. 20, 2020, 1:25 p.m. UTC | #9
Am Mo., 20. Jan. 2020 um 14:18 Uhr schrieb Bodecs Bela <bodecsb@vivanet.hu>:
>
>
> 2020.01.20. 14:02 keltezéssel, Carl Eugen Hoyos írta:
> >
> >>>>>>>> This patch corrects compiler warning about returning possibly uninitialized
> >>>>>>>> variable in hls_write_header function.
> >>>>>>>>
> >>>>>>>> Which compiler warns about this?
> >>>>>> libavformat/hlsenc.c: In function ‘hls_write_header’:
> >>>>>> libavformat/hlsenc.c:2174: warning: ‘ret’ may be used uninitialized in
> >>>>>> this function
> >>>>> Looks like a false positive, does not warn with newer compilers.
> >>>> yes and no.
> >>>>
> >>>> no, because if hls->nb_varstreams == 0, then for loop body never
> >>>> executes and so ret does not get any value.
> >>>>
> >>>> yes, because there is no chance for hls->nb_varstreams to be zero.
> >>>>
> >>>> so, I think setting ret to 0 at its declaration does not do any problem
> >>>> and logically right.
> >>> No, update your compiler instead.
> >> which of my statements did your "No" reference?
> > Both.
>
> Thank you for your help. Maybe due to my poor english, but I really do
> not see,
>
> I really did  test with other compiler and really did not give warning
> any longer,
>
> but it does not help that the ret varaiable remain uninitalized but may
> be returned.
>
> As I know theoretically there is no default value of an int variable.
>
> So why the warning did disappear?

I believe newer compilers detect that hls->nb_varstreams cannot
be zero.

Carl Eugen
Bodecs Bela Jan. 20, 2020, 1:31 p.m. UTC | #10
2020.01.20. 14:25 keltezéssel, Carl Eugen Hoyos írta:
> Am Mo., 20. Jan. 2020 um 14:18 Uhr schrieb Bodecs Bela <bodecsb@vivanet.hu>:
>>
>> 2020.01.20. 14:02 keltezéssel, Carl Eugen Hoyos írta:
>>>>>>>>>> This patch corrects compiler warning about returning possibly uninitialized
>>>>>>>>>> variable in hls_write_header function.
>>>>>>>>>>
>>>>>>>>>> Which compiler warns about this?
>>>>>>>> libavformat/hlsenc.c: In function ‘hls_write_header’:
>>>>>>>> libavformat/hlsenc.c:2174: warning: ‘ret’ may be used uninitialized in
>>>>>>>> this function
>>>>>>> Looks like a false positive, does not warn with newer compilers.
>>>>>> yes and no.
>>>>>>
>>>>>> no, because if hls->nb_varstreams == 0, then for loop body never
>>>>>> executes and so ret does not get any value.
>>>>>>
>>>>>> yes, because there is no chance for hls->nb_varstreams to be zero.
>>>>>>
>>>>>> so, I think setting ret to 0 at its declaration does not do any problem
>>>>>> and logically right.
>>>>> No, update your compiler instead.
>>>> which of my statements did your "No" reference?
>>> Both.
>> Thank you for your help. Maybe due to my poor english, but I really do
>> not see,
>>
>> I really did  test with other compiler and really did not give warning
>> any longer,
>>
>> but it does not help that the ret varaiable remain uninitalized but may
>> be returned.
>>
>> As I know theoretically there is no default value of an int variable.
>>
>> So why the warning did disappear?
> I believe newer compilers detect that hls->nb_varstreams cannot
> be zero.
ok
> Carl Eugen
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
Andreas Rheinhardt Jan. 20, 2020, 10:19 p.m. UTC | #11
On Mon, Jan 20, 2020 at 2:26 PM Carl Eugen Hoyos <ceffmpeg@gmail.com> wrote:

> Am Mo., 20. Jan. 2020 um 14:18 Uhr schrieb Bodecs Bela <bodecsb@vivanet.hu
> >:
> > 2020.01.20. 14:02 keltezéssel, Carl Eugen Hoyos írta:
> > So why the warning did disappear?
>
> I believe newer compilers detect that hls->nb_varstreams cannot
> be zero.
>
>
I don't think so (a compiler has no way to find this out unless it is doing
an LTO-build).
It's probably that the warnings were overly aggressive and have been toned
down.

- Andreas
diff mbox series

Patch

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index d130f03ea62..1661f7aacba 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -2170,7 +2170,7 @@  fail:
 static int hls_write_header(AVFormatContext *s)
 {
     HLSContext *hls = s->priv_data;
-    int ret, i, j;
+    int ret = 0, i, j;
     VariantStream *vs = NULL;
 
     for (i = 0; i < hls->nb_varstreams; i++) {