From ee7929796a593ffc00733037e6c0f19d062a7d06 Mon Sep 17 00:00:00 2001 From: Andrey Nazarov Date: Tue, 10 Aug 2010 15:38:43 +0000 Subject: Allocate pack filename at the end of the memory chunk to avoid alignment issues. --- source/files.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'source/files.c') diff --git a/source/files.c b/source/files.c index 5ceca91..ab8674a 100644 --- a/source/files.c +++ b/source/files.c @@ -129,7 +129,7 @@ typedef struct { packfile_t **file_hash; unsigned hash_size; char *names; - char filename[1]; + char *filename; } pack_t; typedef struct searchpath_s { @@ -1567,21 +1567,21 @@ static pack_t *pack_alloc( FILE *fp, filetype_t type, const char *name, hash_size = Q_CeilPowerOfTwo( num_files / 3 ); - len = strlen( name ); - len = ( len + 3 ) & ~3; - pack = FS_Malloc( sizeof( pack_t ) + len + + len = strlen( name ) + 1; + pack = FS_Malloc( sizeof( pack_t ) + num_files * sizeof( packfile_t ) + hash_size * sizeof( packfile_t * ) + - names_len ); - strcpy( pack->filename, name ); + len + names_len ); pack->type = type; pack->refcount = 0; pack->fp = fp; pack->num_files = num_files; pack->hash_size = hash_size; - pack->files = ( packfile_t * )( ( byte * )pack + sizeof( pack_t ) + len ); + pack->files = ( packfile_t * )( pack + 1 ); pack->file_hash = ( packfile_t ** )( pack->files + num_files ); - pack->names = ( char * )( pack->file_hash + hash_size ); + pack->filename = ( char * )( pack->file_hash + hash_size ); + pack->names = pack->filename + len; + memcpy( pack->filename, name, len ); memset( pack->file_hash, 0, hash_size * sizeof( packfile_t * ) ); return pack; -- cgit v1.2.3