]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
sprite: fix misaligned memory access while loading
authorbones_was_here <bones_was_here@xonotic.au>
Mon, 29 Jan 2024 08:27:48 +0000 (18:27 +1000)
committerbones_was_here <bones_was_here@xonotic.au>
Mon, 29 Jan 2024 15:27:12 +0000 (01:27 +1000)
Signed-off-by: bones_was_here <bones_was_here@xonotic.au>
model_sprite.c

index 44d8f0aee893c34bfbd4bc07b52ec3d401189a6a..5b2e36d7cc72a1346723fed30e7519222da7086e 100644 (file)
@@ -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",