From cf1daafa3f9d5aeff5c7a52c8f2b0e97ea355662 Mon Sep 17 00:00:00 2001
From: Simon McVittie <[EMAIL REDACTED]>
Date: Mon, 9 May 2022 18:48:46 +0100
Subject: [PATCH] cpuinfo: Set padding to 0 if none is needed
It'll be simpler to use overflow detection after this refactor.
Signed-off-by: Simon McVittie <smcv@collabora.com>
---
src/cpuinfo/SDL_cpuinfo.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/cpuinfo/SDL_cpuinfo.c b/src/cpuinfo/SDL_cpuinfo.c
index babbb816c43..53b6366d041 100644
--- a/src/cpuinfo/SDL_cpuinfo.c
+++ b/src/cpuinfo/SDL_cpuinfo.c
@@ -1058,8 +1058,8 @@ void *
SDL_SIMDAlloc(const size_t len)
{
const size_t alignment = SDL_SIMDGetAlignment();
- const size_t padding = alignment - (len % alignment);
- const size_t padded = (padding != alignment) ? (len + padding) : len;
+ const size_t padding = (alignment - (len % alignment)) % alignment;
+ const size_t padded = len + padding;
Uint8 *retval = NULL;
Uint8 *ptr = (Uint8 *) SDL_malloc(padded + alignment + sizeof (void *));
if (ptr) {
@@ -1075,8 +1075,8 @@ void *
SDL_SIMDRealloc(void *mem, const size_t len)
{
const size_t alignment = SDL_SIMDGetAlignment();
- const size_t padding = alignment - (len % alignment);
- const size_t padded = (padding != alignment) ? (len + padding) : len;
+ const size_t padding = (alignment - (len % alignment)) % alignment;
+ const size_t padded = len + padding;
Uint8 *retval = (Uint8*) mem;
void *oldmem = mem;
size_t memdiff = 0, ptrdiff;