mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-03-22 02:11:19 +00:00
[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).
This commit is contained in:
parent
1f811e6310
commit
ef87baf339
2 changed files with 13 additions and 15 deletions
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue