Skip to content

Commit 300cd8a

Browse files
authored
Merge pull request scp-fs2open#7049 from Goober5000/fix_anchor_error_handling
fix handling of invalid arrival/departure anchors
2 parents 3c939f5 + 60b8876 commit 300cd8a

File tree

3 files changed

+21
-17
lines changed

3 files changed

+21
-17
lines changed

code/mission/missionparse.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7654,6 +7654,8 @@ int mission_set_arrival_location(int anchor, ArrivalLocation location, int dist,
76547654
return -1;
76557655

76567656
Assert(anchor >= 0);
7657+
if (anchor < 0)
7658+
return -1; // should never happen, but if it does, fail gracefully
76577659

76587660
// this ship might possibly arrive at another location. The location is based on the
76597661
// proximity of some ship (and some other special tokens)
@@ -8281,7 +8283,9 @@ int mission_do_departure(object *objp, bool goal_is_to_warp)
82818283
if (location == DepartureLocation::TO_DOCK_BAY)
82828284
{
82838285
Assert(anchor >= 0);
8284-
auto anchor_ship_entry = ship_registry_get(Parse_names[anchor]);
8286+
auto anchor_ship_entry = (anchor >= 0)
8287+
? ship_registry_get(Parse_names[anchor])
8288+
: nullptr; // should never happen, but if it does, fail gracefully
82858289

82868290
// see if ship is yet to arrive. If so, then warp.
82878291
if (!anchor_ship_entry || anchor_ship_entry->status == ShipStatus::NOT_YET_PRESENT)

fred2/missionsave.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3722,17 +3722,17 @@ int CFred_mission_save::save_objects()
37223722
}
37233723

37243724
z = shipp->arrival_anchor;
3725-
if (z & SPECIAL_ARRIVAL_ANCHOR_FLAG) {
3725+
if (z < 0) {
3726+
fout(" <error>");
3727+
} else if (z & SPECIAL_ARRIVAL_ANCHOR_FLAG) {
37263728
// get name
37273729
char tmp[NAME_LENGTH + 15];
37283730
stuff_special_arrival_anchor_name(tmp, z, Mission_save_format == FSO_FORMAT_RETAIL ? 1 : 0);
37293731

37303732
// save it
37313733
fout(" %s", tmp);
3732-
} else if (z >= 0) {
3733-
fout(" %s", Ships[z].ship_name);
37343734
} else {
3735-
fout(" <error>");
3735+
fout(" %s", Ships[z].ship_name);
37363736
}
37373737
}
37383738

@@ -5073,17 +5073,17 @@ int CFred_mission_save::save_wings()
50735073
fout("\n$Arrival Anchor:");
50745074

50755075
z = Wings[i].arrival_anchor;
5076-
if (z & SPECIAL_ARRIVAL_ANCHOR_FLAG) {
5076+
if (z < 0) {
5077+
fout(" <error>");
5078+
} else if (z & SPECIAL_ARRIVAL_ANCHOR_FLAG) {
50775079
// get name
50785080
char tmp[NAME_LENGTH + 15];
50795081
stuff_special_arrival_anchor_name(tmp, z, Mission_save_format == FSO_FORMAT_RETAIL ? 1 : 0);
50805082

50815083
// save it
50825084
fout(" %s", tmp);
5083-
} else if (z >= 0) {
5084-
fout(" %s", Ships[z].ship_name);
50855085
} else {
5086-
fout(" <error>");
5086+
fout(" %s", Ships[z].ship_name);
50875087
}
50885088
}
50895089

qtfred/src/mission/missionsave.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3637,17 +3637,17 @@ int CFred_mission_save::save_objects()
36373637
}
36383638

36393639
z = shipp->arrival_anchor;
3640-
if (z & SPECIAL_ARRIVAL_ANCHOR_FLAG) {
3640+
if (z < 0) {
3641+
fout(" <error>");
3642+
} else if (z & SPECIAL_ARRIVAL_ANCHOR_FLAG) {
36413643
// get name
36423644
char tmp[NAME_LENGTH + 15];
36433645
stuff_special_arrival_anchor_name(tmp, z, save_format == MissionFormat::RETAIL);
36443646

36453647
// save it
36463648
fout(" %s", tmp);
3647-
} else if (z >= 0) {
3648-
fout(" %s", Ships[z].ship_name);
36493649
} else {
3650-
fout(" <error>");
3650+
fout(" %s", Ships[z].ship_name);
36513651
}
36523652
}
36533653

@@ -5250,17 +5250,17 @@ int CFred_mission_save::save_wings()
52505250
}
52515251

52525252
z = Wings[i].arrival_anchor;
5253-
if (z & SPECIAL_ARRIVAL_ANCHOR_FLAG) {
5253+
if (z < 0) {
5254+
fout(" <error>");
5255+
} else if (z & SPECIAL_ARRIVAL_ANCHOR_FLAG) {
52545256
// get name
52555257
char tmp[NAME_LENGTH + 15];
52565258
stuff_special_arrival_anchor_name(tmp, z, save_format == MissionFormat::RETAIL);
52575259

52585260
// save it
52595261
fout(" %s", tmp);
5260-
} else if (z >= 0) {
5261-
fout(" %s", Ships[z].ship_name);
52625262
} else {
5263-
fout(" <error>");
5263+
fout(" %s", Ships[z].ship_name);
52645264
}
52655265
}
52665266

0 commit comments

Comments
 (0)