diff mbox series

[FFmpeg-devel,2/2] avutil/samplefmt: don't add offsets to NULL pointers

Message ID 20210607034216.2862-2-jamrial@gmail.com
State Accepted
Commit 8a6103326e165b30510378cbd0e7953910f2b55c
Headers show
Series [FFmpeg-devel,1/2] avutil/samplefmt: remove outdated comment
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

James Almer June 7, 2021, 3:42 a.m. UTC
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavutil/samplefmt.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/libavutil/samplefmt.c b/libavutil/samplefmt.c
index fc077f6444..c7428940e1 100644
--- a/libavutil/samplefmt.c
+++ b/libavutil/samplefmt.c
@@ -160,13 +160,20 @@  int av_samples_fill_arrays(uint8_t **audio_data, int *linesize,
     if (buf_size < 0)
         return buf_size;
 
+    if (linesize)
+        *linesize = line_size;
+
+    memset(audio_data, 0, planar
+                          ? sizeof(*audio_data) * nb_channels
+                          : sizeof(*audio_data));
+
+    if (!buf)
+        return buf_size;
+
     audio_data[0] = (uint8_t *)buf;
     for (ch = 1; planar && ch < nb_channels; ch++)
         audio_data[ch] = audio_data[ch-1] + line_size;
 
-    if (linesize)
-        *linesize = line_size;
-
     return buf_size;
 }