From: michaelni via ffmpeg-devel <ffmpeg-devel@ffmpeg.org>
To: ffmpeg-devel@ffmpeg.org
Cc: michaelni <code@ffmpeg.org>
Subject: [FFmpeg-devel] [PR] avutil/mem: Add av_malloc_with_paddingz() (PR #21509)
Date: Mon, 19 Jan 2026 04:21:45 -0000
Message-ID: <176879650591.25.13669090667799477890@4457048688e7> (raw)
PR #21509 opened by michaelni
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21509
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21509.patch
Add a av_malloc() that adds padding like AV_INPUT_BUFFER_PADDING_SIZE
and clears it.
This is a operation we commonly use so this function should simplify
many cases
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
>From cc424b2a5568ee35a3435ff58a84d2a18c1c6843 Mon Sep 17 00:00:00 2001
From: Michael Niedermayer <michael@niedermayer.cc>
Date: Mon, 19 Jan 2026 05:15:23 +0100
Subject: [PATCH] avutil/mem: Add av_malloc_with_paddingz()
Add a av_malloc() that adds padding like AV_INPUT_BUFFER_PADDING_SIZE
and clears it.
This is a operation we commonly use so this function should simplify
many cases
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
libavutil/mem.c | 10 ++++++++++
libavutil/mem.h | 13 +++++++++++++
2 files changed, 23 insertions(+)
diff --git a/libavutil/mem.c b/libavutil/mem.c
index b205d3fb25..aac7ef4d12 100644
--- a/libavutil/mem.c
+++ b/libavutil/mem.c
@@ -261,6 +261,16 @@ void *av_mallocz(size_t size)
return ptr;
}
+void *av_malloc_with_paddingz(size_t size, size_t padding)
+{
+ if (size > SIZE_MAX - padding)
+ return NULL;
+ uint8_t *p = av_malloc(size + padding);
+ if(p)
+ memset(p + size, 0, padding);
+ return p;
+}
+
void *av_calloc(size_t nmemb, size_t size)
{
size_t result;
diff --git a/libavutil/mem.h b/libavutil/mem.h
index ab7648ac57..6a4c144f18 100644
--- a/libavutil/mem.h
+++ b/libavutil/mem.h
@@ -129,6 +129,19 @@ void *av_malloc(size_t size) av_malloc_attrib av_alloc_size(1);
*/
void *av_mallocz(size_t size) av_malloc_attrib av_alloc_size(1);
+/**
+ * Allocate a memory block with alignment suitable for all memory accesses
+ * (including vectors if available on the CPU)
+ *
+ * An additional padding will be allocated and cleared.
+ *
+ * @param size Size in bytes for the memory block to be allocated
+ * @param padding Size in bytes of padding allocated and zeroed after size.
+ * @return Pointer to the allocated block, or `NULL` if it cannot be allocated
+ * @see av_malloc()
+ */
+void *av_malloc_with_paddingz(size_t size, size_t padding) av_malloc_attrib av_alloc_size(1);
+
/**
* Allocate a memory block for an array with av_malloc().
*
--
2.52.0
_______________________________________________
ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org
To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org
next reply other threads:[~2026-01-19 4:22 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-19 4:21 michaelni via ffmpeg-devel [this message]
2026-01-19 8:44 ` [FFmpeg-devel] " Kieran Kunhya via ffmpeg-devel
2026-01-21 18:38 ` Michael Niedermayer via ffmpeg-devel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=176879650591.25.13669090667799477890@4457048688e7 \
--to=ffmpeg-devel@ffmpeg.org \
--cc=code@ffmpeg.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git