From 341f9108352192141f16cc5b35cd8f971508dbff Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Wed, 12 Mar 2025 11:42:02 -0700 Subject: [PATCH] Initialize the padding of aligned allocations to zero Fixes valgrind uninitialized memory errors when doing SIMD blits e.g. testautomation --filter surface_testScale (cherry picked from commit 3235a4eb4fdb9080f946ed28e9a7f75506272e61) --- src/stdlib/SDL_stdlib.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/stdlib/SDL_stdlib.c b/src/stdlib/SDL_stdlib.c index 98faab95a3..093b2bec47 100644 --- a/src/stdlib/SDL_stdlib.c +++ b/src/stdlib/SDL_stdlib.c @@ -533,6 +533,7 @@ void *SDL_aligned_alloc(size_t alignment, size_t size) { size_t padding; Uint8 *result = NULL; + size_t requested_size = size; if (alignment < sizeof(void*)) { alignment = sizeof(void*); @@ -552,6 +553,11 @@ void *SDL_aligned_alloc(size_t alignment, size_t size) // Store the original pointer right before the returned value SDL_memcpy(result - sizeof(original), &original, sizeof(original)); + + // Initialize the padding to zero + if (padding > 0) { + SDL_memset(result + requested_size, 0, padding); + } } } return result;