Skip to content

Commit 82e2b67

Browse files
committed
remove magic number, static assert about lod level
assumption
1 parent 7f7eed7 commit 82e2b67

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

code/fireball/fireballs.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -408,18 +408,20 @@ void fireball_parse_tbl()
408408
if (fi.lod_count > 1)
409409
{
410410
Assertion(fi.lod_count < MAX_FIREBALL_LOD, "Fireball LOD (%d) greater than MAX_FIREBALL_LOD %d.", fi.lod_count, MAX_FIREBALL_LOD);
411+
static_assert(MAX_FIREBALL_LOD < 10, "The fireball LOD naming scheme needs to be changed for LODs > 9");
411412

412413
auto lod0 = fi.lod[0].filename;
414+
constexpr int MAX_BASENAME_LEN = MAX_FILENAME_LEN - 3; // ensure base file name + _*lod* fits in filename field
413415

414-
if (strlen(lod0) > MAX_FILENAME_LEN - 3)
416+
if (strlen(lod0) > MAX_BASENAME_LEN)
415417
{
416-
Warning(LOCATION, "A fireball base file name may not be longer than %d characters due to the LOD naming scheme.\nLODs other than LOD0 will be skipped for fireball %s", MAX_FILENAME_LEN - 3, lod0);
418+
Warning(LOCATION, "A fireball base file name may not be longer than %d characters due to the LOD naming scheme.\nLODs other than LOD0 will be skipped for fireball %s", MAX_BASENAME_LEN, lod0);
417419
fi.lod_count = 1;
418420
continue;
419421
}
420422

421423
for (int j = 1; j < fi.lod_count; ++j)
422-
sprintf(fi.lod[j].filename, "%.*s_%d", MAX_FILENAME_LEN - 3, lod0, j % MAX_FIREBALL_LOD /*to show gcc12 format string is safe*/);
424+
sprintf(fi.lod[j].filename, "%.*s_%d", MAX_BASENAME_LEN, lod0, j % MAX_FIREBALL_LOD /*to show gcc12 format string is safe*/);
423425
}
424426
}
425427

0 commit comments

Comments
 (0)