From 3af1d5b72226971f08fca869875c4348314dae5c Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Wed, 7 Sep 2016 05:37:01 -0700 Subject: Properly align 16-bit fields in the Hrtf struct --- Alc/hrtf.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/Alc/hrtf.c b/Alc/hrtf.c index 16db0c33..b94faf9d 100644 --- a/Alc/hrtf.c +++ b/Alc/hrtf.c @@ -468,6 +468,7 @@ static struct Hrtf *LoadHrtf00(const ALubyte *data, size_t datalen, const_al_str { size_t total = sizeof(struct Hrtf); total += sizeof(azCount[0])*evCount; + total = (total+1)&~1; /* Align for (u)short fields */ total += sizeof(evOffset[0])*evCount; total += sizeof(coeffs[0])*irSize*irCount; total += sizeof(delays[0])*irCount; @@ -483,14 +484,18 @@ static struct Hrtf *LoadHrtf00(const ALubyte *data, size_t datalen, const_al_str if(!failed) { + char *base = (char*)Hrtf; + uintptr_t offset = sizeof(*Hrtf); + Hrtf->sampleRate = rate; Hrtf->irSize = irSize; Hrtf->evCount = evCount; - Hrtf->azCount = ((ALubyte*)(Hrtf+1)); - Hrtf->evOffset = ((ALushort*)(Hrtf->azCount + evCount)); - Hrtf->coeffs = ((ALshort*)(Hrtf->evOffset + evCount)); - Hrtf->delays = ((ALubyte*)(Hrtf->coeffs + irSize*irCount)); - Hrtf->filename = ((char*)(Hrtf->delays + irCount)); + Hrtf->azCount = ((ALubyte*)(base + offset)); offset += evCount*sizeof(Hrtf->azCount[0]); + offset = (offset+1)&~1; /* Align for (u)short fields */ + Hrtf->evOffset = ((ALushort*)(base + offset)); offset += evCount*sizeof(Hrtf->evOffset[0]); + Hrtf->coeffs = ((ALshort*)(base + offset)); offset += irSize*irCount*sizeof(Hrtf->coeffs[0]); + Hrtf->delays = ((ALubyte*)(base + offset)); offset += irCount*sizeof(Hrtf->delays[0]); + Hrtf->filename = ((char*)(base + offset)); Hrtf->next = NULL; memcpy((void*)Hrtf->azCount, azCount, sizeof(azCount[0])*evCount); @@ -644,6 +649,7 @@ static struct Hrtf *LoadHrtf01(const ALubyte *data, size_t datalen, const_al_str { size_t total = sizeof(struct Hrtf); total += sizeof(azCount[0])*evCount; + total = (total+1)&~1; /* Align for (u)short fields */ total += sizeof(evOffset[0])*evCount; total += sizeof(coeffs[0])*irSize*irCount; total += sizeof(delays[0])*irCount; @@ -659,14 +665,18 @@ static struct Hrtf *LoadHrtf01(const ALubyte *data, size_t datalen, const_al_str if(!failed) { + char *base = (char*)Hrtf; + uintptr_t offset = sizeof(*Hrtf); + Hrtf->sampleRate = rate; Hrtf->irSize = irSize; Hrtf->evCount = evCount; - Hrtf->azCount = ((ALubyte*)(Hrtf+1)); - Hrtf->evOffset = ((ALushort*)(Hrtf->azCount + evCount)); - Hrtf->coeffs = ((ALshort*)(Hrtf->evOffset + evCount)); - Hrtf->delays = ((ALubyte*)(Hrtf->coeffs + irSize*irCount)); - Hrtf->filename = ((char*)(Hrtf->delays + irCount)); + Hrtf->azCount = ((ALubyte*)(base + offset)); offset += evCount*sizeof(Hrtf->azCount[0]); + offset = (offset+1)&~1; /* Align for (u)short fields */ + Hrtf->evOffset = ((ALushort*)(base + offset)); offset += evCount*sizeof(Hrtf->evOffset[0]); + Hrtf->coeffs = ((ALshort*)(base + offset)); offset += irSize*irCount*sizeof(Hrtf->coeffs[0]); + Hrtf->delays = ((ALubyte*)(base + offset)); offset += irCount*sizeof(Hrtf->delays[0]); + Hrtf->filename = ((char*)(base + offset)); Hrtf->next = NULL; memcpy((void*)Hrtf->azCount, azCount, sizeof(azCount[0])*evCount); -- cgit v1.2.3