From: bones_was_here Date: Mon, 29 Jan 2024 08:27:48 +0000 (+1000) Subject: sprite: fix misaligned memory access while loading X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=0d5f8f0edd073d7ff233bde3995b529c0fcb67ff;p=xonotic%2Fdarkplaces.git sprite: fix misaligned memory access while loading Signed-off-by: bones_was_here --- diff --git a/model_sprite.c b/model_sprite.c index 44d8f0ae..5b2e36d7 100644 --- a/model_sprite.c +++ b/model_sprite.c @@ -298,6 +298,7 @@ void Mod_IDSP_Load(model_t *mod, void *buffer, void *bufferend) unsigned char palette[256][4]; const unsigned char *in; dspritehl_t *pinhlsprite; + unsigned char *aligneddata; pinhlsprite = (dspritehl_t *)datapointer; datapointer += sizeof(dspritehl_t); @@ -361,7 +362,11 @@ void Mod_IDSP_Load(model_t *mod, void *buffer, void *bufferend) return; } - Mod_Sprite_SharedSetup(datapointer, LittleLong (pinhlsprite->version), (unsigned int *)(&palette[0][0]), rendermode == SPRHL_ADDITIVE); + // the above datapointer arithmetic causes misaligned access + aligneddata = (unsigned char *)Mem_Alloc(tempmempool, (unsigned char *)bufferend - datapointer); + memcpy(aligneddata, datapointer, (unsigned char *)bufferend - datapointer); + Mod_Sprite_SharedSetup(aligneddata, LittleLong (pinhlsprite->version), (unsigned int *)(&palette[0][0]), rendermode == SPRHL_ADDITIVE); + Mem_Free(aligneddata); } else Host_Error("Mod_IDSP_Load: %s has wrong version number (%i). Only %i (quake), %i (HalfLife), and %i (sprite32) supported",