On Mon, 19 Jan 2026, 04:22 michaelni via ffmpeg-devel, < [email protected]> wrote:
> 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 <[email protected]> > > > >From cc424b2a5568ee35a3435ff58a84d2a18c1c6843 Mon Sep 17 00:00:00 2001 > From: Michael Niedermayer <[email protected]> > 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 <[email protected]> > --- > 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 -- [email protected] > To unsubscribe send an email to [email protected] Seems a bit wordy. av_malloc_paddedz instead? Kieran _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
