diff --git a/src/client/refresh/files/models.c b/src/client/refresh/files/models.c index 9c5c2990..d135a246 100644 --- a/src/client/refresh/files/models.c +++ b/src/client/refresh/files/models.c @@ -1495,7 +1495,7 @@ Mod_LoadModel_MD3(const char *mod_name, const void *buffer, int modfilelen, { const md3_shader_t *md3_shader = (md3_shader_t*)((byte*)buffer + meshofs + LittleLong(md3_mesh->ofs_shaders)) + j; - strncpy(skin, md3_shader->name, Q_min(sizeof(md3_shader->name), MAX_SKINNAME) - 1); + memcpy(skin, md3_shader->name, Q_min(sizeof(md3_shader->name), MAX_SKINNAME)); skin += MAX_SKINNAME; } diff --git a/src/common/collision.c b/src/common/collision.c index 680a360e..fbfd3e08 100644 --- a/src/common/collision.c +++ b/src/common/collision.c @@ -111,7 +111,7 @@ typedef struct int numclusters; int numvisibility; - char *map_entitystring; + const char *map_entitystring; int numentitychars; int extradatasize; @@ -1651,7 +1651,7 @@ CMod_LoadAreaPortals(const char *name, const dareaportal_t **map_areaportals, qb } static void -CMod_LoadEntityString(const char *name, char **map_entitystring, int *numentitychars, +CMod_LoadEntityString(const char *name, const char **map_entitystring, int *numentitychars, const byte *cmod_base, const lump_t *l) { if (sv_entfile->value) @@ -1688,14 +1688,15 @@ CMod_LoadEntityString(const char *name, char **map_entitystring, int *numentityc if (buffer != NULL && bufLen > 1) { - Com_Printf (".ent file %s loaded.\n", entname); + char *entity; *numentitychars = bufLen; - *map_entitystring = Hunk_Alloc(bufLen + 1); - - memcpy(*map_entitystring, buffer, bufLen); - (*map_entitystring)[bufLen] = 0; /* jit entity bug - null terminate the entity string! */ + entity = Hunk_Alloc(bufLen); + memcpy(entity, buffer, bufLen); FS_FreeFile(buffer); + + Com_Printf (".ent file %s loaded.\n", entname); + *map_entitystring = entity; return; } else if (bufLen != -1) @@ -1713,9 +1714,7 @@ CMod_LoadEntityString(const char *name, char **map_entitystring, int *numentityc Com_Error(ERR_DROP, "%s: Map has too small entity lump", __func__); } - *map_entitystring = Hunk_Alloc(l->filelen + 1); - memcpy(*map_entitystring, cmod_base + l->fileofs, l->filelen); - (*map_entitystring)[l->filelen] = 0; + *map_entitystring = (const char *)cmod_base + l->fileofs; } static void @@ -1974,9 +1973,10 @@ CM_NumInlineModels(void) return cmod->numcmodels; } -char * -CM_EntityString(void) +const char * +CM_EntityString(int *size) { + *size = cmod->numentitychars; return cmod->map_entitystring; } diff --git a/src/common/header/common.h b/src/common/header/common.h index 2a934161..383b86de 100644 --- a/src/common/header/common.h +++ b/src/common/header/common.h @@ -643,7 +643,7 @@ void CM_ModFreeAll(void); int CM_NumClusters(void); int CM_NumInlineModels(void); -char *CM_EntityString(void); +const char *CM_EntityString(int *size); /* creates a clipping hull for an arbitrary box */ int CM_HeadnodeForBox(vec3_t mins, vec3_t maxs); diff --git a/src/server/sv_init.c b/src/server/sv_init.c index 99eb2ff3..8f188e58 100644 --- a/src/server/sv_init.c +++ b/src/server/sv_init.c @@ -194,8 +194,10 @@ static void SV_SpawnServer(char *server, char *spawnpoint, server_state_t serverstate, qboolean attractloop, qboolean loadgame, qboolean isautosave) { - int i; + const char *entity_orig; unsigned checksum; + char *entity; + int i, entitysize; if (attractloop) { @@ -286,8 +288,21 @@ SV_SpawnServer(char *server, char *spawnpoint, server_state_t serverstate, sv.state = ss_loading; Com_SetServerState(sv.state); + /* copy original entities string */ + entity_orig = CM_EntityString(&entitysize); + if (entitysize < 0) + { + entitysize = 0; + } + entity = malloc(entitysize + 1); + if (entitysize) + { + memcpy(entity, entity_orig, entitysize); + } + entity[entitysize] = 0; /* jit entity bug - null terminate the entity string! */ /* load and spawn all other entities */ - ge->SpawnEntities(sv.name, CM_EntityString(), spawnpoint); + ge->SpawnEntities(sv.name, entity, spawnpoint); + free(entity); /* run two frames to allow everything to settle */ ge->RunFrame();