fix alignment issues reported by ubsan on x64

Fix chd lzma and zlib buffers alignment
Fix ChannelEx struct alignment
This commit is contained in:
Flyinghead 2020-03-14 22:23:13 +01:00
parent e3313d27b2
commit ad3dce1102
2 changed files with 8 additions and 8 deletions

View File

@ -448,7 +448,7 @@ void *lzma_fast_alloc(void *p, size_t size)
}
/* alloc a new one and put it into the list */
uint32_t *addr = (uint32_t *)malloc(sizeof(uint8_t) * (size + sizeof(uint32_t)));
uint32_t *addr = (uint32_t *)malloc(sizeof(uint8_t) * size + sizeof(uintptr_t));
if (addr==NULL)
return NULL;
for (int scan = 0; scan < MAX_LZMA_ALLOCS; scan++)
@ -462,7 +462,7 @@ void *lzma_fast_alloc(void *p, size_t size)
/* set the low bit of the size so we don't match next time */
*addr = size | 1;
return addr + 1;
return addr + (sizeof(uint32_t) == sizeof(uintptr_t) ? 1 : 2);
}
/*-------------------------------------------------
@ -479,7 +479,7 @@ void lzma_fast_free(void *p, void *address)
lzma_allocator *codec = (lzma_allocator *)(p);
/* find the hunk */
uint32_t *ptr = (uint32_t *)(address) - 1;
uint32_t *ptr = (uint32_t *)(address) - (sizeof(uint32_t) == sizeof(uintptr_t) ? 1 : 2);
for (int scan = 0; scan < MAX_LZMA_ALLOCS; scan++)
{
if (ptr == codec->allocptr[scan])
@ -2466,7 +2466,7 @@ static voidpf zlib_fast_alloc(voidpf opaque, uInt items, uInt size)
}
/* alloc a new one */
ptr = (UINT32 *)malloc(size + sizeof(UINT32));
ptr = (UINT32 *)malloc(size + sizeof(uintptr_t));
if (!ptr)
return NULL;
@ -2480,7 +2480,7 @@ static voidpf zlib_fast_alloc(voidpf opaque, uInt items, uInt size)
/* set the low bit of the size so we don't match next time */
*ptr = size | 1;
return ptr + 1;
return ptr + (sizeof(uint32_t) == sizeof(uintptr_t) ? 1 : 2);
}
/*-------------------------------------------------
@ -2491,7 +2491,7 @@ static voidpf zlib_fast_alloc(voidpf opaque, uInt items, uInt size)
static void zlib_fast_free(voidpf opaque, voidpf address)
{
zlib_allocator *alloc = (zlib_allocator *)opaque;
UINT32 *ptr = (UINT32 *)address - 1;
UINT32 *ptr = (UINT32 *)address - (sizeof(uint32_t) == sizeof(uintptr_t) ? 1 : 2);
int i;
/* find the hunk */

View File

@ -152,7 +152,7 @@ s16 pl=0,pr=0;
DSP_OUT_VOL_REG* dsp_out_vol;
#pragma pack (1)
#pragma pack(push, 1)
//All regs are 16b , aligned to 32b (upper bits 0?)
struct ChannelCommonData
{
@ -294,7 +294,7 @@ struct ChannelCommonData
u32 pad_20:16;
};
#pragma pack(pop)
enum _EG_state