diff mbox series

[FFmpeg-devel,20/35] avdevice/avdevice: clean up avdevice_capabilities_create

Message ID 20210607230414.612-21-dcnieho@gmail.com
State Superseded, archived
Headers show
Series avdevice (mostly dshow) enhancements | expand

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

Diederick C. Niehorster June 7, 2021, 11:03 p.m. UTC
Draw implementation in line with that of avdevice_list_devices

Signed-off-by: Diederick Niehorster <dcnieho@gmail.com>
---
 libavdevice/avdevice.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

Comments

Nicolas George June 8, 2021, 12:09 p.m. UTC | #1
Diederick Niehorster (12021-06-08):
> Draw implementation in line with that of avdevice_list_devices
> 
> Signed-off-by: Diederick Niehorster <dcnieho@gmail.com>
> ---
>  libavdevice/avdevice.c | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/libavdevice/avdevice.c b/libavdevice/avdevice.c
> index 695b9143af..d73d36e1dd 100644
> --- a/libavdevice/avdevice.c
> +++ b/libavdevice/avdevice.c
> @@ -100,12 +100,15 @@ int avdevice_capabilities_create(AVDeviceCapabilitiesQuery **caps, AVFormatConte
>                                   AVDictionary **device_options)
>  {
>      int ret;
> -    av_assert0(s && caps);
> +    av_assert0(s);
> +    av_assert0(caps);
>      av_assert0(s->iformat || s->oformat);
>      if ((s->oformat && !s->oformat->create_device_capabilities) ||
> -        (s->iformat && !s->iformat->create_device_capabilities))
> +        (s->iformat && !s->iformat->create_device_capabilities)) {
> +        *caps = NULL;
>          return AVERROR(ENOSYS);
> -    *caps = av_mallocz(sizeof(**caps));
> +    }

> +    *caps = av_mallocz(sizeof(AVDeviceCapabilitiesQuery));

var = malloc(sizeof(*var)) is preferred over var = malloc(type), because
if you change the type of var, it happens in another part of the code
and you would have to remember to change it here too.

>      if (!(*caps))
>          return AVERROR(ENOMEM);
>      (*caps)->device_context = s;

Regards,
Diederick C. Niehorster June 8, 2021, 8:33 p.m. UTC | #2
On Tue, Jun 8, 2021 at 2:09 PM Nicolas George <george@nsup.org> wrote:
>
> Diederick Niehorster (12021-06-08):
> > -    *caps = av_mallocz(sizeof(**caps));
> > +    *caps = av_mallocz(sizeof(AVDeviceCapabilitiesQuery));
>
> var = malloc(sizeof(*var)) is preferred over var = malloc(type), because
> if you change the type of var, it happens in another part of the code
> and you would have to remember to change it here too.

Reverted.

Thanks,
Dee
diff mbox series

Patch

diff --git a/libavdevice/avdevice.c b/libavdevice/avdevice.c
index 695b9143af..d73d36e1dd 100644
--- a/libavdevice/avdevice.c
+++ b/libavdevice/avdevice.c
@@ -100,12 +100,15 @@  int avdevice_capabilities_create(AVDeviceCapabilitiesQuery **caps, AVFormatConte
                                  AVDictionary **device_options)
 {
     int ret;
-    av_assert0(s && caps);
+    av_assert0(s);
+    av_assert0(caps);
     av_assert0(s->iformat || s->oformat);
     if ((s->oformat && !s->oformat->create_device_capabilities) ||
-        (s->iformat && !s->iformat->create_device_capabilities))
+        (s->iformat && !s->iformat->create_device_capabilities)) {
+        *caps = NULL;
         return AVERROR(ENOSYS);
-    *caps = av_mallocz(sizeof(**caps));
+    }
+    *caps = av_mallocz(sizeof(AVDeviceCapabilitiesQuery));
     if (!(*caps))
         return AVERROR(ENOMEM);
     (*caps)->device_context = s;