From: bones_was_here Date: Fri, 9 Feb 2024 09:14:59 +0000 (+1000) Subject: Fix two memory allocation issues X-Git-Url: http://git.xonotic.org/?p=xonotic%2Fdarkplaces.git;a=commitdiff_plain;h=e73dfbb6367cb7bffe644e0eb070c0d31fa2e824;ds=sidebyside Fix two memory allocation issues In fa06dd40f48b20d738b6bd604758c81defd76cfd I misunderstood the subdivision code, causing sentinel2 to be written past the end of the buffer... somehow many maps and games worked fine despite this. This commit reverts the bad line from that commit. A very old (div0-stable) bug when loading Q1BSP meant we didn't allocate enough texture memory when a "sky" texture name wasn't all lowercase, causing a crash when loading custom map e2m9. Signed-off-by: bones_was_here --- diff --git a/model_brush.c b/model_brush.c index 092682b0..3357d0df 100644 --- a/model_brush.c +++ b/model_brush.c @@ -1683,6 +1683,10 @@ static void Mod_Q1BSP_LoadTextures(sizebuf_t *sb) // pretty up the buffer (replacing any trailing garbage with 0) for (j = (int)strlen(name); j < 16; j++) name[j] = 0; + // bones_was_here: force all names to lowercase (matching code below) so we don't crash on e2m9 + for (j = 0;name[j];j++) + if (name[j] >= 'A' && name[j] <= 'Z') + name[j] += 'a' - 'A'; if (!strncmp(name, "sky", 3)) numsky++; diff --git a/zone.c b/zone.c index 1fb9da39..dce455d1 100644 --- a/zone.c +++ b/zone.c @@ -397,8 +397,7 @@ void *_Mem_Alloc(mempool_t *pool, void *olddata, size_t size, size_t alignment, //if (developer.integer > 0 && developer_memorydebug.integer) // _Mem_CheckSentinelsGlobal(filename, fileline); pool->totalsize += size; - // calculate the smallest realsize that is a multiple of alignment - realsize = (sizeof(memheader_t) + size + sizeof(sentinel2) + (alignment-1)) & ~(alignment-1); + realsize = alignment + sizeof(memheader_t) + size + sizeof(sentinel2); pool->realsize += realsize; base = (unsigned char *)Clump_AllocBlock(realsize); if (base == NULL)