mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-06-14 02:07:49 +00:00
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 3235a4eb4f)
This commit is contained in:
parent
84dff407d4
commit
341f910835
1 changed files with 6 additions and 0 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue