]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
Fix two memory allocation issues
authorbones_was_here <bones_was_here@xonotic.au>
Fri, 9 Feb 2024 09:14:59 +0000 (19:14 +1000)
committerbones_was_here <bones_was_here@xonotic.au>
Fri, 9 Feb 2024 10:12:15 +0000 (20:12 +1000)
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 <bones_was_here@xonotic.au>
model_brush.c
zone.c

index 092682b0de9dd5d673315bb9ce497e598b1d191a..3357d0dfe6968920bd025a6d2afc7f1e7c76f380 100644 (file)
@@ -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 1fb9da3931f4a0d6ba576ab9e45307c035230f3e..dce455d126ff16f852486e920d384de3b345c3fc 100644 (file)
--- 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)