Skip to content

Commit 42dd1eb

Browse files
authored
Merge pull request scp-fs2open#6713 from Goober5000/various_small_issues
Various Coverity issues
2 parents 1e8ea06 + ceee045 commit 42dd1eb

41 files changed

Lines changed: 149 additions & 174 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

code/actions/expression/ExpressionParser.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,9 @@ class ExpressionBuilderVisitor : public ActionExpressionVisitor {
122122
}
123123
antlrcpp::Any visitVec3d_constructor(ActionExpressionParser::Vec3d_constructorContext* context) override
124124
{
125-
auto xExpression = visit(context->expression(0)).as<std::shared_ptr<nodes::AbstractExpression>>();
126-
auto yExpression = visit(context->expression(1)).as<std::shared_ptr<nodes::AbstractExpression>>();
127-
auto zExpression = visit(context->expression(2)).as<std::shared_ptr<nodes::AbstractExpression>>();
125+
const auto xExpression = visit(context->expression(0)).as<std::shared_ptr<nodes::AbstractExpression>>();
126+
const auto yExpression = visit(context->expression(1)).as<std::shared_ptr<nodes::AbstractExpression>>();
127+
const auto zExpression = visit(context->expression(2)).as<std::shared_ptr<nodes::AbstractExpression>>();
128128

129129
auto expression = std::make_shared<nodes::VectorConstructorExpression>(context->L_PAREN()->getSymbol(),
130130
xExpression,

code/actions/types/MoveToSubmodel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ ActionResult MoveToSubmodel::execute(ProgramLocals& locals) const
5555

5656
// We need to do a linear search for the right subobject
5757
for (int i = 0; i < pm->n_models; ++i) {
58-
const auto submodel = pm->submodel[i];
58+
const auto& submodel = pm->submodel[i];
5959

6060
if (subsystem_stricmp(destinationSubObject.c_str(), submodel.name) == 0) {
6161
// Found something!

code/controlconfig/controlsconfig.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1348,7 +1348,7 @@ bool control_config_accept(bool API_Access)
13481348

13491349
// Pack the current bindings into a preset, then save the file
13501350
CC_preset preset;
1351-
preset.name = str;
1351+
preset.name = std::move(str);
13521352
std::copy(Control_config.begin(), Control_config.end(), std::back_inserter(preset.bindings));
13531353
Control_config_presets.push_back(preset);
13541354
save_preset_file(preset, true);

code/hud/hudbrackets.cpp

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,6 @@ void HudGaugeBrackets::renderObjectBrackets(object *targetp, color *clr, int w_c
398398
int x1,x2,y1,y2;
399399
bool draw_box = true;
400400
int bound_rc;
401-
SCP_list<CJumpNode>::iterator jnp;
402401

403402

404403
bool not_player_target = (Player_ai->target_objnum < 0 || targetp != &Objects[Player_ai->target_objnum]);
@@ -449,13 +448,11 @@ void HudGaugeBrackets::renderObjectBrackets(object *targetp, color *clr, int w_c
449448
break;
450449

451450
case OBJ_JUMP_NODE:
452-
for (jnp = Jump_nodes.begin(); jnp != Jump_nodes.end(); ++jnp) {
453-
if(jnp->GetSCPObject() == targetp)
454-
break;
455-
}
456-
457-
modelnum = jnp->GetModelNumber();
451+
{
452+
auto jnp = jumpnode_get_by_objp(targetp);
453+
modelnum = jnp ? jnp->GetModelNumber() : -1;
458454
bound_rc = model_find_2d_bound_min( modelnum, &targetp->orient, &targetp->pos,&x1,&y1,&x2,&y2 );
455+
}
459456
break;
460457

461458
default:
@@ -637,7 +634,6 @@ void HudGaugeBrackets::renderBoundingBrackets(int x1, int y1, int x2, int y2, in
637634
const char* tinfo_class = NULL;
638635
char temp_name[NAME_LENGTH*2+3];
639636
char temp_class[NAME_LENGTH];
640-
SCP_list<CJumpNode>::iterator jnp;
641637

642638
switch(t_objp->type) {
643639
case OBJ_SHIP:
@@ -676,11 +672,8 @@ void HudGaugeBrackets::renderBoundingBrackets(int x1, int y1, int x2, int y2, in
676672
}
677673
break;
678674
case OBJ_JUMP_NODE:
679-
for (jnp = Jump_nodes.begin(); jnp != Jump_nodes.end(); ++jnp) {
680-
if(jnp->GetSCPObjectNumber() == target_objnum)
681-
break;
682-
}
683-
tinfo_name = jnp->GetDisplayName();
675+
auto jnp = jumpnode_get_by_objnum(target_objnum);
676+
tinfo_name = jnp ? jnp->GetDisplayName() : "";
684677
break;
685678
}
686679

code/hud/hudsquadmsg.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ void hud_squadmsg_start()
207207
auto paramList = scripting::hook_param_list(scripting::hook_param("Player", 'o', Player_obj));
208208
if (scripting::hooks::OnHudCommMenuOpened->isOverride(paramList))
209209
{
210-
scripting::hooks::OnHudCommMenuOpened->run(paramList);
210+
scripting::hooks::OnHudCommMenuOpened->run(std::move(paramList));
211211
return;
212212
}
213213
}
@@ -243,7 +243,7 @@ void hud_squadmsg_end()
243243
auto paramList = scripting::hook_param_list(scripting::hook_param("Player", 'o', Player_obj));
244244
if (scripting::hooks::OnHudCommMenuClosed->isOverride(paramList))
245245
{
246-
scripting::hooks::OnHudCommMenuClosed->run(paramList);
246+
scripting::hooks::OnHudCommMenuClosed->run(std::move(paramList));
247247
return;
248248
}
249249
}
@@ -2007,7 +2007,7 @@ void hud_squadmsg_reinforcement_select()
20072007
}
20082008

20092009
Assert ( Num_menu_items < MAX_MENU_ITEMS );
2010-
MsgItems[Num_menu_items].text = rp_name;
2010+
MsgItems[Num_menu_items].text = std::move(rp_name);
20112011
MsgItems[Num_menu_items].instance = i;
20122012
MsgItems[Num_menu_items].active = 0;
20132013

code/hud/hudtarget.cpp

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -620,16 +620,11 @@ void hud_reticle_list_update(object *objp, float measure, int dot_flag)
620620
{
621621
reticle_list *rl, *new_rl;
622622
int i;
623-
SCP_list<CJumpNode>::iterator jnp;
624623

625624
if (objp->type == OBJ_JUMP_NODE) {
626-
for (jnp = Jump_nodes.begin(); jnp != Jump_nodes.end(); ++jnp) {
627-
if( jnp->GetSCPObject() != objp )
628-
continue;
629-
630-
if( jnp->IsHidden() )
631-
return;
632-
}
625+
auto jnp = jumpnode_get_by_objp(objp);
626+
if (!jnp || jnp->IsHidden())
627+
return;
633628
}
634629

635630
for ( rl = GET_FIRST(&Reticle_cur_list); rl != END_OF_LIST(&Reticle_cur_list); rl = GET_NEXT(rl) ) {
@@ -1168,7 +1163,6 @@ void hud_target_common(int team_mask, int next_flag)
11681163
object *A, *start, *start2;
11691164
ship *shipp;
11701165
int is_ship, target_found = FALSE;
1171-
SCP_list<CJumpNode>::iterator jnp;
11721166

11731167
if (Player_ai->target_objnum == -1)
11741168
start = &obj_used_list;
@@ -1209,14 +1203,10 @@ void hud_target_common(int team_mask, int next_flag)
12091203
}
12101204

12111205
if (A->type == OBJ_JUMP_NODE) {
1212-
for (jnp = Jump_nodes.begin(); jnp != Jump_nodes.end(); ++jnp) {
1213-
if( jnp->GetSCPObject() == A )
1214-
break;
1215-
}
1206+
auto jnp = jumpnode_get_by_objp(A);
1207+
Assertion(jnp, "Failed to find jump node with object index %d; trace out and fix!\n", OBJ_INDEX(A));
12161208

1217-
Assertion(jnp != Jump_nodes.end(), "Failed to find jump node with object index %d; trace out and fix!\n", OBJ_INDEX(A));
1218-
1219-
if( jnp->IsHidden() )
1209+
if( !jnp || jnp->IsHidden() )
12201210
continue;
12211211
}
12221212

@@ -2419,7 +2409,6 @@ void hud_target_targets_target()
24192409
int object_targetable_in_reticle(object *target_objp)
24202410
{
24212411
int obj_type;
2422-
SCP_list<CJumpNode>::iterator jnp;
24232412

24242413
if (target_objp == Player_obj ) {
24252414
return 0;
@@ -2430,12 +2419,12 @@ int object_targetable_in_reticle(object *target_objp)
24302419
if ( (obj_type == OBJ_SHIP) || (obj_type == OBJ_DEBRIS) || (obj_type == OBJ_WEAPON) || (obj_type == OBJ_ASTEROID) )
24312420
{
24322421
return 1;
2433-
} else if ( obj_type == OBJ_JUMP_NODE )
2422+
}
2423+
else if ( obj_type == OBJ_JUMP_NODE )
24342424
{
2435-
for (jnp = Jump_nodes.begin(); jnp != Jump_nodes.end(); ++jnp) {
2436-
if(jnp->GetSCPObject() == target_objp)
2437-
break;
2438-
}
2425+
auto jnp = jumpnode_get_by_objp(target_objp);
2426+
if (!jnp)
2427+
return 0;
24392428

24402429
if (!jnp->IsHidden())
24412430
return 1;
@@ -2465,7 +2454,6 @@ void hud_target_in_reticle_new()
24652454
object *A;
24662455
mc_info mc;
24672456
float dist;
2468-
SCP_list<CJumpNode>::iterator jnp;
24692457

24702458
hud_reticle_clear_list(&Reticle_cur_list);
24712459
Reticle_save_timestamp = timestamp(RESET_TARGET_IN_RETICLE);
@@ -2523,12 +2511,12 @@ void hud_target_in_reticle_new()
25232511
}
25242512
break;
25252513
case OBJ_JUMP_NODE:
2526-
for (jnp = Jump_nodes.begin(); jnp != Jump_nodes.end(); ++jnp) {
2527-
if(jnp->GetSCPObject() == A)
2528-
break;
2529-
}
2530-
2514+
{
2515+
auto jnp = jumpnode_get_by_objp(A);
2516+
if (!jnp)
2517+
continue;
25312518
mc.model_num = jnp->GetModelNumber();
2519+
}
25322520
break;
25332521
default:
25342522
Int3(); // Illegal object type.

code/jumpnode/jumpnode.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,24 @@ CJumpNode *jumpnode_get_by_objnum(int objnum)
494494
return nullptr;
495495
}
496496

497+
/**
498+
* Get jump node object by the object pointer
499+
*
500+
* @param objp to search for
501+
* @return Jump node object pointer
502+
*/
503+
CJumpNode *jumpnode_get_by_objp(const object *objp)
504+
{
505+
Assert(objp != nullptr);
506+
507+
for (CJumpNode &jnp : Jump_nodes) {
508+
if (jnp.GetSCPObject() == objp)
509+
return &(jnp);
510+
}
511+
512+
return nullptr;
513+
}
514+
497515
/**
498516
* Given an object, returns which jump node it's inside (if any)
499517
*

code/jumpnode/jumpnode.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ extern SCP_list<CJumpNode> Jump_nodes;
9393
//-----Functions-----
9494
CJumpNode *jumpnode_get_by_name(const char *name);
9595
CJumpNode *jumpnode_get_by_objnum(int objnum);
96+
CJumpNode *jumpnode_get_by_objp(const object *objp);
9697
CJumpNode *jumpnode_get_which_in(const object *objp);
9798

9899
void jumpnode_render_all();

code/menuui/credits.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -874,8 +874,8 @@ void credits_do_frame(float /*frametime*/)
874874
// Check if the text part is actually visible
875875
if (Credit_position + y_offset + height > 0.0f)
876876
{
877-
float x = static_cast<float>((gr_screen.clip_width_unscaled - width) / 2);
878-
gr_string(x, Credit_position + y_offset, iter->c_str() + currentPos, GR_RESIZE_MENU, 1.0f, length);
877+
int x = (gr_screen.clip_width_unscaled - width) / 2;
878+
gr_string(i2fl(x), Credit_position + y_offset, iter->c_str() + currentPos, GR_RESIZE_MENU, 1.0f, length);
879879
}
880880

881881
y_offset += height;

code/mission/missionparse.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6657,9 +6657,9 @@ bool post_process_mission(mission *pm)
66576657
if (MULTI_TEAM) {
66586658
team = Net_player->p_info.team;
66596659
}
6660-
auto br = Briefings[team].stages;
6660+
const auto &br = Briefings[team].stages;
66616661
for (i = 0; i < Briefings[team].num_stages; i++) {
6662-
auto stage = br[i];
6662+
const auto &stage = br[i];
66636663
for (int j = 0; j < stage.num_icons; j++) {
66646664
stage.icons[j].modelnum = model_load(Ship_info[stage.icons[j].ship_class].pof_file);
66656665
}

0 commit comments

Comments
 (0)