diff mbox series

[FFmpeg-devel,2/5] avformat/iamf_writer: Remove nonsense check

Message ID AS8P250MB0744AA967B5AA65AA65F5FC78F512@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM
State Accepted
Commit 840f192540ccf261561cf3ccedf8a8b91421f66b
Headers show
Series [FFmpeg-devel,1/5] avformat/iamf_writer: Don't leak on error when adding ParamDefinition | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/configure_x86 warning Failed to apply patch

Commit Message

Andreas Rheinhardt Feb. 19, 2024, 9:52 p.m. UTC
Checking whether a pointer to an element of an array is NULL
makes no sense, as the pointer addition involved in getting
the address would be undefined behaviour already if the array
were NULL.
In this case the array allocation has already been checked
a few lines before.
Fixes Coverity issue #1559548.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavformat/iamf_writer.c | 2 --
 1 file changed, 2 deletions(-)

Comments

James Almer Feb. 19, 2024, 9:57 p.m. UTC | #1
On 2/19/2024 6:52 PM, Andreas Rheinhardt wrote:
> Checking whether a pointer to an element of an array is NULL
> makes no sense, as the pointer addition involved in getting
> the address would be undefined behaviour already if the array
> were NULL.
> In this case the array allocation has already been checked
> a few lines before.
> Fixes Coverity issue #1559548.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
>   libavformat/iamf_writer.c | 2 --
>   1 file changed, 2 deletions(-)
> 
> diff --git a/libavformat/iamf_writer.c b/libavformat/iamf_writer.c
> index 897b06310f..e0c47b5e9d 100644
> --- a/libavformat/iamf_writer.c
> +++ b/libavformat/iamf_writer.c
> @@ -251,8 +251,6 @@ int ff_iamf_add_audio_element(IAMFContext *iamf, const AVStreamGroup *stg, void
>           int nb_channels = iamf_audio_element->layers[i]->ch_layout.nb_channels;
>   
>           IAMFLayer *layer = &audio_element->layers[i];
> -        if (!layer)
> -            return AVERROR(ENOMEM);
>           memset(layer, 0, sizeof(*layer));
>   
>           if (i)

LGTM. I noticed this while rewriting the mp4 implementation, but forgot 
to deal with it.
diff mbox series

Patch

diff --git a/libavformat/iamf_writer.c b/libavformat/iamf_writer.c
index 897b06310f..e0c47b5e9d 100644
--- a/libavformat/iamf_writer.c
+++ b/libavformat/iamf_writer.c
@@ -251,8 +251,6 @@  int ff_iamf_add_audio_element(IAMFContext *iamf, const AVStreamGroup *stg, void
         int nb_channels = iamf_audio_element->layers[i]->ch_layout.nb_channels;
 
         IAMFLayer *layer = &audio_element->layers[i];
-        if (!layer)
-            return AVERROR(ENOMEM);
         memset(layer, 0, sizeof(*layer));
 
         if (i)