summaryrefslogtreecommitdiff
path: root/source/files.c
diff options
context:
space:
mode:
authorAndrey Nazarov <skuller@skuller.net>2010-08-10 15:38:43 +0000
committerAndrey Nazarov <skuller@skuller.net>2010-08-10 15:38:43 +0000
commitee7929796a593ffc00733037e6c0f19d062a7d06 (patch)
treefad5d686c026dbf07f4cc60de64f392e1f2c0327 /source/files.c
parenta3e844197b2984a33307799e28209b1072e1da64 (diff)
Allocate pack filename at the end of the memory chunk to avoid alignment issues.
Diffstat (limited to 'source/files.c')
-rw-r--r--source/files.c16
1 files changed, 8 insertions, 8 deletions
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;