From ef87baf339ff5d1c9ea4523a29e31fdb6fb90f6c Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Thu, 12 May 2022 23:40:52 +0900 Subject: [PATCH] [model] Undo brush texture changes in 4f58429137 While gcc was quite correct in its warning, all I needed was to explicitly truncate the string. I don't remember why I didn't do that back when I made the changes in 4f58429137, but it works now, and the surrounding code does expect the string to be no more than 15 chars long. This fixes yet another memory leak (but timedemo over multiple runs still leaks like a sieve). --- include/QF/model.h | 2 +- libs/models/brush/model_brush.c | 26 ++++++++++++-------------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/include/QF/model.h b/include/QF/model.h index 308175a5e..89e0b8730 100644 --- a/include/QF/model.h +++ b/include/QF/model.h @@ -89,7 +89,7 @@ typedef struct instsurf_s { } instsurf_t; typedef struct texture_s { - char *name; + char name[16]; unsigned width, height; void *render; // renderer specific data int anim_total; // total tenths in sequence ( 0 = no) diff --git a/libs/models/brush/model_brush.c b/libs/models/brush/model_brush.c index a13ed16ba..7632c07f2 100644 --- a/libs/models/brush/model_brush.c +++ b/libs/models/brush/model_brush.c @@ -219,28 +219,26 @@ Mod_LeafPVS_mix (const mleaf_t *leaf, const model_t *model, byte defvis, static void mod_unique_miptex_name (texture_t **textures, texture_t *tx, int ind) { - char *name; + char name[17]; int num = 0, i; - dstring_t *tag = 0; + const char *tag; - name = tx->name; + strncpy (name, tx->name, 16); + name[16] = 0; do { for (i = 0; i < ind; i++) if (textures[i] && !strcmp (textures[i]->name, tx->name)) break; if (i == ind) break; - if (!tag) { - tag = dstring_new (); - } - dsprintf (tag, "%s~%x", name, num++); - tx->name = tag->str; + tag = va (0, "~%x", num++); + strncpy (tx->name, name, 16); + tx->name[15] = 0; + if (strlen (name) + strlen (tag) <= 15) + strcat (tx->name, tag); + else + strcpy (tx->name + 15 - strlen (tag), tag); } while (1); - - if (tag) { - tx->name = dstring_freeze (tag); - free(name); - } } static void @@ -280,7 +278,7 @@ Mod_LoadTextures (model_t *mod, bsp_t *bsp) brush->textures[i] = tx; - tx->name = strndup(mt->name, sizeof (mt->name)); + memcpy (tx->name, mt->name, sizeof (tx->name)); mod_unique_miptex_name (brush->textures, tx, i); tx->width = mt->width; tx->height = mt->height;