From 4021d7bf5c25f539d91a6d93f752b95b2d83ba45 Mon Sep 17 00:00:00 2001 From: nillerusr Date: Mon, 17 Feb 2020 23:25:39 +0300 Subject: [PATCH] imagelib: fix unaligned access --- engine/common/imagelib/img_wad.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/engine/common/imagelib/img_wad.c b/engine/common/imagelib/img_wad.c index 8a19d8bc..6a47a9e2 100644 --- a/engine/common/imagelib/img_wad.c +++ b/engine/common/imagelib/img_wad.c @@ -199,8 +199,9 @@ Image_LoadSPR */ qboolean Image_LoadSPR( const char *name, const byte *buffer, fs_offset_t filesize ) { - dspriteframe_t *pin; // identical for q1\hl sprites + dspriteframe_t pin; // identical for q1\hl sprites qboolean truecolor = false; + byte *fin; if( image.hint == IL_HINT_HL ) { @@ -217,9 +218,9 @@ qboolean Image_LoadSPR( const char *name, const byte *buffer, fs_offset_t filesi return false; } - pin = (dspriteframe_t *)buffer; - image.width = pin->width; - image.height = pin->height; + memcpy( &pin, buffer, sizeof(dspriteframe_t) ); + image.width = pin.width; + image.height = pin.height; if( filesize < image.width * image.height ) return false; @@ -243,18 +244,19 @@ qboolean Image_LoadSPR( const char *name, const byte *buffer, fs_offset_t filesi SetBits( image.flags, IMAGE_HAS_ALPHA ); break; } + + fin = (byte *)(buffer + sizeof(dspriteframe_t)); if( truecolor ) { // spr32 support image.size = image.width * image.height * 4; image.rgba = Mem_Malloc( host.imagepool, image.size ); - memcpy( image.rgba, (byte *)(pin + 1), image.size ); + memcpy( image.rgba, fin, image.size ); SetBits( image.flags, IMAGE_HAS_COLOR ); // Color. True Color! return true; } - - return Image_AddIndexedImageToPack( (byte *)(pin + 1), image.width, image.height ); + return Image_AddIndexedImageToPack( fin, image.width, image.height ); } /*