Skip to content

Commit 3455b0f

Browse files
authored
Merge pull request scp-fs2open#7458 from Goober5000/cleanup/coverity_and_claude
a bit of cleanup
2 parents 20b55eb + f8fa1e4 commit 3455b0f

2 files changed

Lines changed: 25 additions & 17 deletions

File tree

code/ai/aigoals.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,8 @@ void ai_add_goal_sub_player(ai_goal_type type, ai_goal_mode mode, int submode, c
825825
// friendlies want to rearm at the same time. The support ship forgets what it's doing and flies
826826
// off to repair somebody while still docked. I reproduced this with retail, so it's not a bug in
827827
// my new docking code. :)
828-
int ai_goal_find_empty_slot( ai_goal *goals, int active_goal )
828+
// Note that this function is now where Purge_when_new_goal_added is checked to set the Purge flag.
829+
int ai_goal_allocate_slot( ai_goal *goals, int active_goal )
829830
{
830831
int oldest_index = -1, first_empty_index = -1;
831832

@@ -915,7 +916,7 @@ void ai_add_ship_goal_scripting(ai_goal_mode mode, int submode, int priority, co
915916
int empty_index;
916917
ai_goal *aigp;
917918

918-
empty_index = ai_goal_find_empty_slot(aip->goals, aip->active_goal);
919+
empty_index = ai_goal_allocate_slot(aip->goals, aip->active_goal);
919920
aigp = &aip->goals[empty_index];
920921
ai_add_goal_sub_scripting(ai_goal_type::PLAYER_SHIP, mode, submode, priority, shipname, aigp, int_data, float_data);
921922

@@ -939,7 +940,7 @@ void ai_add_ship_goal_player(ai_goal_type type, ai_goal_mode mode, int submode,
939940
int empty_index;
940941
ai_goal *aigp;
941942

942-
empty_index = ai_goal_find_empty_slot( aip->goals, aip->active_goal );
943+
empty_index = ai_goal_allocate_slot( aip->goals, aip->active_goal );
943944
aigp = &aip->goals[empty_index];
944945
ai_add_goal_sub_player( type, mode, submode, shipname, aigp, int_data, float_data, lua_target );
945946

@@ -973,7 +974,7 @@ void ai_add_wing_goal_player(ai_goal_type type, ai_goal_mode mode, int submode,
973974
// add the sexpression index into the wing's list of goal sexpressions if
974975
// there are more waves to come. We use the same method here as when adding a goal to
975976
// a ship -- find the first empty entry. If none exists, take the oldest entry and replace it.
976-
empty_index = ai_goal_find_empty_slot( wingp->ai_goals, -1 );
977+
empty_index = ai_goal_allocate_slot( wingp->ai_goals, -1 );
977978
ai_add_goal_sub_player( type, mode, submode, shipname, &wingp->ai_goals[empty_index], int_data, float_data, lua_target );
978979
}
979980

@@ -1613,7 +1614,7 @@ void ai_add_ship_goal_sexp( int sexp, ai_goal_type type, ai_info *aip )
16131614
{
16141615
int gindex;
16151616

1616-
gindex = ai_goal_find_empty_slot( aip->goals, aip->active_goal );
1617+
gindex = ai_goal_allocate_slot( aip->goals, aip->active_goal );
16171618
ai_add_goal_sub_sexp( sexp, type, aip, &aip->goals[gindex], Ships[aip->shipnum].ship_name );
16181619
}
16191620

@@ -1637,7 +1638,7 @@ void ai_add_wing_goal_sexp(int sexp, ai_goal_type type, wing *wingp)
16371638
if ((wingp->num_waves - wingp->current_wave > 0) || Fred_running) {
16381639
int gindex;
16391640

1640-
gindex = ai_goal_find_empty_slot( wingp->ai_goals, -1 );
1641+
gindex = ai_goal_allocate_slot( wingp->ai_goals, -1 );
16411642
ai_add_goal_sub_sexp( sexp, type, nullptr, &wingp->ai_goals[gindex], wingp->name );
16421643
}
16431644
}
@@ -1660,7 +1661,7 @@ void ai_add_goal_ship_internal( ai_info *aip, int goal_type, char *name, int /*
16601661
Assertion(strcmp(name, Ships[aip->shipnum].ship_name) != 0, "The goals apply to the actor in ai_add_goal_ship_internal for ship %s, please report to the SCP!", name);
16611662

16621663
// find an empty slot to put this goal in.
1663-
gindex = ai_goal_find_empty_slot( aip->goals, aip->active_goal );
1664+
gindex = ai_goal_allocate_slot( aip->goals, aip->active_goal );
16641665
aigp = &(aip->goals[gindex]);
16651666
ai_goal_reset(aigp, true);
16661667

@@ -1789,7 +1790,7 @@ ai_achievability ai_mission_goal_achievable( int objnum, ai_goal *aigp )
17891790
if (!target_ship_entry || !target_ship_entry->has_shipp())
17901791
return ai_achievability::NOT_ACHIEVABLE;
17911792

1792-
// the override flag is now set in the calling function, ai_mission_goal_achievable
1793+
// the override flag is now set in the calling function, validate_mission_goals
17931794
return ai_achievability::ACHIEVABLE;
17941795
}
17951796

code/parse/sexp.cpp

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2689,7 +2689,10 @@ int check_sexp_syntax(int node, int desired_return_type, int recursive, int *bad
26892689
}
26902690
break;
26912691
}
2692-
Assert(ship_node >= 0);
2692+
if (ship_node < 0) {
2693+
Warning(LOCATION, "Could not find ship node for operator %s!", Operators[op_index].text.c_str());
2694+
return SEXP_CHECK_INVALID_SHIP;
2695+
}
26932696

26942697
if (is_node_value_dynamic(ship_node)) {
26952698
const int dyn_val_check = check_dynamic_value_node_type(ship_node, true, false);
@@ -4034,7 +4037,10 @@ int check_sexp_syntax(int node, int desired_return_type, int recursive, int *bad
40344037
}
40354038

40364039
p_container = get_sexp_container(Sexp_nodes[node].text);
4037-
Assertion(p_container, "Attempt to use unknown container %s. Please report!", Sexp_nodes[node].text);
4040+
if (!p_container) {
4041+
Warning(LOCATION, "Attempt to use unknown container %s. Please report!", Sexp_nodes[node].text);
4042+
return SEXP_CHECK_TYPE_MISMATCH;
4043+
}
40384044

40394045
if ((desired_argument_type == OPF_LIST_CONTAINER_NAME && !p_container->is_list()) ||
40404046
(desired_argument_type == OPF_MAP_CONTAINER_NAME && !p_container->is_map())) {
@@ -4044,10 +4050,10 @@ int check_sexp_syntax(int node, int desired_return_type, int recursive, int *bad
40444050
}
40454051

40464052
case OPF_CONTAINER_VALUE:
4047-
Assertion(p_container,
4048-
"Attempt to check value arg for null container for SEXP operator %d at arg %d. Please report!",
4049-
op_const,
4050-
argnum);
4053+
if (!p_container) {
4054+
Warning(LOCATION, "Attempt to check value arg for null container for SEXP operator %s at arg %d. Please report!", Operators[op_index].text.c_str(), argnum);
4055+
return SEXP_CHECK_TYPE_MISMATCH;
4056+
}
40514057
z = check_container_value_data_type(op_const,
40524058
argnum,
40534059
p_container->type,
@@ -4063,9 +4069,10 @@ int check_sexp_syntax(int node, int desired_return_type, int recursive, int *bad
40634069
if (node_subtype == SEXP_ATOM_CONTAINER_NAME) {
40644070
// only list containers of strings or map containers with string keys are allowed
40654071
const auto *p_str_container = get_sexp_container(Sexp_nodes[node].text);
4066-
Assertion(p_str_container,
4067-
"Attempt to use unknown container %s. Please report!",
4068-
Sexp_nodes[node].text);
4072+
if (!p_str_container) {
4073+
Warning(LOCATION, "Attempt to use unknown container %s. Please report!", Sexp_nodes[node].text);
4074+
return SEXP_CHECK_TYPE_MISMATCH;
4075+
}
40694076

40704077
const auto &str_container = *p_str_container;
40714078
if (str_container.is_list() && none(str_container.type & ContainerType::STRING_DATA)) {

0 commit comments

Comments
 (0)