diff mbox series

[FFmpeg-devel] avformat/protocols: fix discarded-qualifiers compiler warning

Message ID 20210214165228.11547-1-nuomi2021@gmail.com
State New
Headers show
Series [FFmpeg-devel] avformat/protocols: fix discarded-qualifiers compiler warning
Related show

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Nuo Mi Feb. 14, 2021, 4:52 p.m. UTC
---
 libavformat/protocols.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Carl Eugen Hoyos Feb. 14, 2021, 4:58 p.m. UTC | #1
Am So., 14. Feb. 2021 um 17:53 Uhr schrieb Nuo Mi <nuomi2021@gmail.com>:
>
> ---
>  libavformat/protocols.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/libavformat/protocols.c b/libavformat/protocols.c
> index 7df18fbb3b..0b43f66baf 100644
> --- a/libavformat/protocols.c
> +++ b/libavformat/protocols.c
> @@ -111,10 +111,10 @@ const AVClass *ff_urlcontext_child_class_iterate(void **iter)
>
>  const char *avio_enum_protocols(void **opaque, int output)
>  {
> -    const URLProtocol **p = *opaque;
> +    const URLProtocol *const *p = *opaque;
>
>      p = p ? p + 1 : url_protocols;
> -    *opaque = p;
> +    *opaque = (void*)p;

I suspect that this is wrong, only avconv's protocols were const.

Carl Eugen
Paul B Mahol Feb. 14, 2021, 5 p.m. UTC | #2
On Sun, Feb 14, 2021 at 5:58 PM Carl Eugen Hoyos <ceffmpeg@gmail.com> wrote:

> Am So., 14. Feb. 2021 um 17:53 Uhr schrieb Nuo Mi <nuomi2021@gmail.com>:
> >
> > ---
> >  libavformat/protocols.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/libavformat/protocols.c b/libavformat/protocols.c
> > index 7df18fbb3b..0b43f66baf 100644
> > --- a/libavformat/protocols.c
> > +++ b/libavformat/protocols.c
> > @@ -111,10 +111,10 @@ const AVClass
> *ff_urlcontext_child_class_iterate(void **iter)
> >
> >  const char *avio_enum_protocols(void **opaque, int output)
> >  {
> > -    const URLProtocol **p = *opaque;
> > +    const URLProtocol *const *p = *opaque;
> >
> >      p = p ? p + 1 : url_protocols;
> > -    *opaque = p;
> > +    *opaque = (void*)p;
>
> I suspect that this is wrong, only avconv's protocols were const.
>
>
That is not valid explanation.


> 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 Feb. 14, 2021, 5:12 p.m. UTC | #3
Am So., 14. Feb. 2021 um 18:00 Uhr schrieb Paul B Mahol <onemda@gmail.com>:
>
> On Sun, Feb 14, 2021 at 5:58 PM Carl Eugen Hoyos <ceffmpeg@gmail.com> wrote:
>
> > Am So., 14. Feb. 2021 um 17:53 Uhr schrieb Nuo Mi <nuomi2021@gmail.com>:
> > >
> > > ---
> > >  libavformat/protocols.c | 4 ++--
> > >  1 file changed, 2 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/libavformat/protocols.c b/libavformat/protocols.c
> > > index 7df18fbb3b..0b43f66baf 100644
> > > --- a/libavformat/protocols.c
> > > +++ b/libavformat/protocols.c
> > > @@ -111,10 +111,10 @@ const AVClass
> > *ff_urlcontext_child_class_iterate(void **iter)
> > >
> > >  const char *avio_enum_protocols(void **opaque, int output)
> > >  {
> > > -    const URLProtocol **p = *opaque;
> > > +    const URLProtocol *const *p = *opaque;
> > >
> > >      p = p ? p + 1 : url_protocols;
> > > -    *opaque = p;
> > > +    *opaque = (void*)p;
> >
> > I suspect that this is wrong, only avconv's protocols were const.
> >
> >
> That is not valid explanation.

The warning is a regression since a merge commit from Clement (?),
FFmpeg's protocols are not const iirc.

Carl Eugen
Paul B Mahol Feb. 14, 2021, 5:39 p.m. UTC | #4
On Sun, Feb 14, 2021 at 6:36 PM Carl Eugen Hoyos <ceffmpeg@gmail.com> wrote:

> Am So., 14. Feb. 2021 um 18:00 Uhr schrieb Paul B Mahol <onemda@gmail.com
> >:
> >
> > On Sun, Feb 14, 2021 at 5:58 PM Carl Eugen Hoyos <ceffmpeg@gmail.com>
> wrote:
> >
> > > Am So., 14. Feb. 2021 um 17:53 Uhr schrieb Nuo Mi <nuomi2021@gmail.com
> >:
> > > >
> > > > ---
> > > >  libavformat/protocols.c | 4 ++--
> > > >  1 file changed, 2 insertions(+), 2 deletions(-)
> > > >
> > > > diff --git a/libavformat/protocols.c b/libavformat/protocols.c
> > > > index 7df18fbb3b..0b43f66baf 100644
> > > > --- a/libavformat/protocols.c
> > > > +++ b/libavformat/protocols.c
> > > > @@ -111,10 +111,10 @@ const AVClass
> > > *ff_urlcontext_child_class_iterate(void **iter)
> > > >
> > > >  const char *avio_enum_protocols(void **opaque, int output)
> > > >  {
> > > > -    const URLProtocol **p = *opaque;
> > > > +    const URLProtocol *const *p = *opaque;
> > > >
> > > >      p = p ? p + 1 : url_protocols;
> > > > -    *opaque = p;
> > > > +    *opaque = (void*)p;
> > >
> > > I suspect that this is wrong, only avconv's protocols were const.
> > >
> > >
> > That is not valid explanation.
>
> The warning is a regression since a merge commit from Clement (?),
> FFmpeg's protocols are not const iirc.


Look at every protocol definition, they are const.


>
>
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 Feb. 14, 2021, 6:04 p.m. UTC | #5
Carl Eugen Hoyos:
> Am So., 14. Feb. 2021 um 18:00 Uhr schrieb Paul B Mahol <onemda@gmail.com>:
>>
>> On Sun, Feb 14, 2021 at 5:58 PM Carl Eugen Hoyos <ceffmpeg@gmail.com> wrote:
>>
>>> Am So., 14. Feb. 2021 um 17:53 Uhr schrieb Nuo Mi <nuomi2021@gmail.com>:
>>>>
>>>> ---
>>>>  libavformat/protocols.c | 4 ++--
>>>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>>>
>>>> diff --git a/libavformat/protocols.c b/libavformat/protocols.c
>>>> index 7df18fbb3b..0b43f66baf 100644
>>>> --- a/libavformat/protocols.c
>>>> +++ b/libavformat/protocols.c
>>>> @@ -111,10 +111,10 @@ const AVClass
>>> *ff_urlcontext_child_class_iterate(void **iter)
>>>>
>>>>  const char *avio_enum_protocols(void **opaque, int output)
>>>>  {
>>>> -    const URLProtocol **p = *opaque;
>>>> +    const URLProtocol *const *p = *opaque;
>>>>
>>>>      p = p ? p + 1 : url_protocols;
>>>> -    *opaque = p;
>>>> +    *opaque = (void*)p;
>>>
>>> I suspect that this is wrong, only avconv's protocols were const.
>>>
>>>
>> That is not valid explanation.
> 
> The warning is a regression since a merge commit from Clement (?),
> FFmpeg's protocols are not const iirc.
> 
It is irrelevant whether they are const: The above warning exists
because avio_enum_protocols returns a pointer to nonconst that points to
an entry of the const url_protocols array (i.e. it points to a const
pointer (that points to something const, but that doesn't matter)).
There are two ways to fix this: The first is by only giving the user a
pointer to const which requires changing the function signature. I once
sent such a patch, see
https://patchwork.ffmpeg.org/project/ffmpeg/patch/20190821090438.10260-2-andreas.rheinhardt@gmail.com/.
The second way requires casts. The typical way to do so is to give the
user an index in the array of protocols (by casting the pointer to
intptr_t).

- Andreas
Nuo Mi Feb. 14, 2021, 6:23 p.m. UTC | #6
On Mon, Feb 15, 2021 at 2:04 AM Andreas Rheinhardt <
andreas.rheinhardt@gmail.com> wrote:

> Carl Eugen Hoyos:
> > Am So., 14. Feb. 2021 um 18:00 Uhr schrieb Paul B Mahol <
> onemda@gmail.com>:
> >>
> >> On Sun, Feb 14, 2021 at 5:58 PM Carl Eugen Hoyos <ceffmpeg@gmail.com>
> wrote:
> >>
> >>> Am So., 14. Feb. 2021 um 17:53 Uhr schrieb Nuo Mi <nuomi2021@gmail.com
> >:
> >>>>
> >>>> ---
> >>>>  libavformat/protocols.c | 4 ++--
> >>>>  1 file changed, 2 insertions(+), 2 deletions(-)
> >>>>
> >>>> diff --git a/libavformat/protocols.c b/libavformat/protocols.c
> >>>> index 7df18fbb3b..0b43f66baf 100644
> >>>> --- a/libavformat/protocols.c
> >>>> +++ b/libavformat/protocols.c
> >>>> @@ -111,10 +111,10 @@ const AVClass
> >>> *ff_urlcontext_child_class_iterate(void **iter)
> >>>>
> >>>>  const char *avio_enum_protocols(void **opaque, int output)
> >>>>  {
> >>>> -    const URLProtocol **p = *opaque;
> >>>> +    const URLProtocol *const *p = *opaque;
> >>>>
> >>>>      p = p ? p + 1 : url_protocols;
> >>>> -    *opaque = p;
> >>>> +    *opaque = (void*)p;
> >>>
> >>> I suspect that this is wrong, only avconv's protocols were const.
> >>>
> >>>
> >> That is not valid explanation.
> >
> > The warning is a regression since a merge commit from Clement (?),
> > FFmpeg's protocols are not const iirc.
> >
> It is irrelevant whether they are const: The above warning exists
> because avio_enum_protocols returns a pointer to nonconst that points to
> an entry of the const url_protocols array (i.e. it points to a const
> pointer (that points to something const, but that doesn't matter)).
> There are two ways to fix this: The first is by only giving the user a
> pointer to const which requires changing the function signature. I once
> sent such a patch, see
>
> https://patchwork.ffmpeg.org/project/ffmpeg/patch/20190821090438.10260-2-andreas.rheinhardt@gmail.com/
> .
> The second way requires casts. The typical way to do so is to give the
> user an index in the array of protocols (by casting the pointer to
> intptr_t).
>
I think give the user an int may be better than a pointer. we do not need
to change the signature and we can check the boundary.

>
> - 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".
diff mbox series

Patch

diff --git a/libavformat/protocols.c b/libavformat/protocols.c
index 7df18fbb3b..0b43f66baf 100644
--- a/libavformat/protocols.c
+++ b/libavformat/protocols.c
@@ -111,10 +111,10 @@  const AVClass *ff_urlcontext_child_class_iterate(void **iter)
 
 const char *avio_enum_protocols(void **opaque, int output)
 {
-    const URLProtocol **p = *opaque;
+    const URLProtocol *const *p = *opaque;
 
     p = p ? p + 1 : url_protocols;
-    *opaque = p;
+    *opaque = (void*)p;
     if (!*p) {
         *opaque = NULL;
         return NULL;