Skip to content

Commit 0ab523b

Browse files
authored
Merge pull request #4462 from the-maddin/fix-gcc12-warnings
Fix gcc12 warnings
2 parents d72c5db + 82e2b67 commit 0ab523b

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

code/fireball/fireballs.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,10 +407,21 @@ void fireball_parse_tbl()
407407
{
408408
if (fi.lod_count > 1)
409409
{
410+
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");
412+
410413
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
415+
416+
if (strlen(lod0) > MAX_BASENAME_LEN)
417+
{
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);
419+
fi.lod_count = 1;
420+
continue;
421+
}
411422

412423
for (int j = 1; j < fi.lod_count; ++j)
413-
sprintf(fi.lod[j].filename, "%s_%d", lod0, j);
424+
sprintf(fi.lod[j].filename, "%.*s_%d", MAX_BASENAME_LEN, lod0, j % MAX_FIREBALL_LOD /*to show gcc12 format string is safe*/);
414425
}
415426
}
416427

code/ship/ship.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4616,7 +4616,7 @@ static void parse_ship_values(ship_info* sip, const bool is_template, const bool
46164616
}
46174617
for (auto it = Ship_info.cbegin(); it != Ship_info.cend(); ++it) {
46184618
//find the index number of the current ship info type
4619-
if (it->name == sip->name) {
4619+
if (&(*it) == sip) {
46204620
Ai_tp_list[i].ship_class.push_back((int)std::distance(Ship_info.cbegin(), it));
46214621
break;
46224622
}
@@ -20263,4 +20263,4 @@ int ship_check_visibility(const ship* viewed, ship* viewer)
2026320263
}
2026420264

2026520265
return ship_is_visible;
20266-
}
20266+
}

0 commit comments

Comments
 (0)