From 83ff4783c28478ba188434099823894a061266c9 Mon Sep 17 00:00:00 2001 From: bjorn Date: Tue, 4 Aug 2020 12:23:45 -0600 Subject: [PATCH] ALIGN macro aligns up instead of down; So you don't have to add (n - 1). Hopefully this turns out to be the common case. --- src/core/util.h | 2 +- src/modules/data/textureData.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/util.h b/src/core/util.h index 24669769..518b329f 100644 --- a/src/core/util.h +++ b/src/core/util.h @@ -32,7 +32,7 @@ #define MAX(a, b) (a > b ? a : b) #define MIN(a, b) (a < b ? a : b) #define CLAMP(x, min, max) MAX(min, MIN(max, x)) -#define ALIGN(p, n) ((uintptr_t) (p) & -n) +#define ALIGN(p, n) (((uintptr_t) (p) + (n - 1)) & -n) #define CHECK_SIZEOF(T) int(*_o)[sizeof(T)]=1 typedef struct Color { float r, g, b, a; } Color; diff --git a/src/modules/data/textureData.c b/src/modules/data/textureData.c index e528f5d9..f0cf7685 100644 --- a/src/modules/data/textureData.c +++ b/src/modules/data/textureData.c @@ -388,7 +388,7 @@ static bool parseKTX(uint8_t* bytes, size_t size, TextureData* textureData) { textureData->mipmaps[i] = (Mipmap) { .width = width, .height = height, .data = data.u8 + sizeof(uint32_t), .size = *data.u32 }; width = MAX(width >> 1, 1u); height = MAX(height >> 1, 1u); - data.u8 = (uint8_t*) ALIGN(data.u8 + sizeof(uint32_t) + *data.u32 + 3, 4); + data.u8 = (uint8_t*) ALIGN(data.u8 + sizeof(uint32_t) + *data.u32, 4); } return true;