From c9a46b3e758c3de7208ed0f1a2af616d72d14441 Mon Sep 17 00:00:00 2001 From: John Fernandez Date: Fri, 3 Nov 2023 22:03:53 -0400 Subject: [PATCH 01/10] Don't need to remove this flag Since we are explicitly setting the exact flag values. For coverity 1320526 --- code/parse/sexp.cpp | 1 - code/pilotfile/csg.cpp | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/code/parse/sexp.cpp b/code/parse/sexp.cpp index 92dc72a7ba2..a1a5c8a5840 100644 --- a/code/parse/sexp.cpp +++ b/code/parse/sexp.cpp @@ -34127,7 +34127,6 @@ void add_block_variable(const char *text, const char *var_name, int type, int in strcpy_s(Block_variables[index].text, text); strcpy_s(Block_variables[index].variable_name, var_name); - Block_variables[index].type &= ~SEXP_VARIABLE_NOT_USED; Block_variables[index].type = (type | SEXP_VARIABLE_SET); } diff --git a/code/pilotfile/csg.cpp b/code/pilotfile/csg.cpp index f8172897e0f..1eaae38ce61 100644 --- a/code/pilotfile/csg.cpp +++ b/code/pilotfile/csg.cpp @@ -130,7 +130,8 @@ void pilotfile::csg_read_info() Assertion ((idx < (int)ship_list.size()), "Campaign file contains an incorrect value for the last flown ship class. No data in ship_list for ship number %d.", idx); if (idx >= (int)ship_list.size()) idx = -1; - else if (idx != -1) + + if (idx != -1) p->last_ship_flown_si_index = ship_list[idx].index; else p->last_ship_flown_si_index = -1; From 9a4b05edcea0572a36260d879462b69617c198bb Mon Sep 17 00:00:00 2001 From: John Fernandez Date: Fri, 3 Nov 2023 22:10:35 -0400 Subject: [PATCH 02/10] Remove this line Since it would be overwritten next line anyway. For coverity 1320527 --- code/parse/sexp.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/code/parse/sexp.cpp b/code/parse/sexp.cpp index a1a5c8a5840..de0f9d71f9e 100644 --- a/code/parse/sexp.cpp +++ b/code/parse/sexp.cpp @@ -34153,7 +34153,6 @@ int sexp_add_variable(const char *text, const char *var_name, int type, int inde if (index >= 0) { strcpy_s(Sexp_variables[index].text, text); strcpy_s(Sexp_variables[index].variable_name, var_name); - Sexp_variables[index].type &= ~SEXP_VARIABLE_NOT_USED; Sexp_variables[index].type = (type | SEXP_VARIABLE_SET); } From f18bf6e70ee64bcc3cb06a19cfc617cabe95793b Mon Sep 17 00:00:00 2001 From: John Fernandez Date: Fri, 3 Nov 2023 22:23:32 -0400 Subject: [PATCH 03/10] This assignment is never used. For coverity 1523417 --- code/missionui/missionshipchoice.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/code/missionui/missionshipchoice.cpp b/code/missionui/missionshipchoice.cpp index 8136e6473bf..72a06872e9d 100644 --- a/code/missionui/missionshipchoice.cpp +++ b/code/missionui/missionshipchoice.cpp @@ -2466,7 +2466,6 @@ commit_pressed_status create_wings(bool API_Access) } objnum = OBJ_INDEX(Player_obj); - shipnum = Objects[objnum].instance; } else { // We should always update the parse object information, even if the ship is present at start, // because the wing might have more than one wave or scripting functions might need accurate data From e558effe392ca181a64ed1a4d7ba98241332596c Mon Sep 17 00:00:00 2001 From: John Fernandez Date: Fri, 3 Nov 2023 22:29:54 -0400 Subject: [PATCH 04/10] Fix copy paste Bug This was originally `glBlendFunc(GL_ONE, GL_ZERO);` `blendfunc_Value[0] = GL_ONE;` `blendfunc_Value[1] = GL_ZERO;` Marked by coverity 1523247 --- code/graphics/opengl/gropenglstate.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/graphics/opengl/gropenglstate.cpp b/code/graphics/opengl/gropenglstate.cpp index 70cc6430526..b3fcd75f65e 100644 --- a/code/graphics/opengl/gropenglstate.cpp +++ b/code/graphics/opengl/gropenglstate.cpp @@ -182,7 +182,7 @@ void opengl_state::init() glBlendFunc(GL_ONE, GL_ZERO); blendfunc_Value.first = GL_ONE; - blendfunc_Value.first = GL_ZERO; + blendfunc_Value.second = GL_ZERO; buffer_blendfunc_Value.fill(blendfunc_Value); glDepthFunc(GL_LESS); From e53137473d3c72cb0b35f567feb13ef925d6bd6d Mon Sep 17 00:00:00 2001 From: John Fernandez Date: Fri, 3 Nov 2023 22:34:39 -0400 Subject: [PATCH 05/10] Move this declaration So that linters and coverity don't complain about the initial value being overwritten. Coverity 1320531 --- code/starfield/starfield.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/code/starfield/starfield.cpp b/code/starfield/starfield.cpp index 1c4c0d7e8ce..37c179c5498 100644 --- a/code/starfield/starfield.cpp +++ b/code/starfield/starfield.cpp @@ -1762,7 +1762,6 @@ void stars_draw_stars() int i; star *sp; - float dist = 0.0f; float ratio; vDist vDst; vertex p1, p2; @@ -1813,7 +1812,7 @@ void stars_draw_stars() } if ( can_draw && (Star_flags & (STAR_FLAG_TAIL|STAR_FLAG_DIM)) ) { - dist = vm_vec_dist_quick( &sp->last_star_pos, &p2.world ); + float dist = vm_vec_dist_quick( &sp->last_star_pos, &p2.world ); if ( dist > Star_max_length ) { ratio = Star_max_length / dist; From a071238bf8aac39d9f066b1ccabfb634201600e0 Mon Sep 17 00:00:00 2001 From: John Fernandez Date: Fri, 3 Nov 2023 22:48:26 -0400 Subject: [PATCH 06/10] Remove unused setting of storage_idx For coverity 1522980 --- code/ship/ship.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/code/ship/ship.cpp b/code/ship/ship.cpp index 12497f1af50..f1402808061 100644 --- a/code/ship/ship.cpp +++ b/code/ship/ship.cpp @@ -19836,7 +19836,6 @@ float ArmorType::GetDamage(float damage_applied, int in_damage_type_idx, float d // Nuke: idiotproof this, no segfault 4 u if ( (storage_idx < 0) || (storage_idx >= AT_NUM_STORAGE_LOCATIONS) ) { Warning(LOCATION, "+Value: for +Store: calculation out of range. Should be between 0 and %i. Read: %i, Skipping calculation.", AT_NUM_STORAGE_LOCATIONS, storage_idx); - storage_idx = 0; } else { storage[storage_idx] = damage_applied; } @@ -19850,7 +19849,6 @@ float ArmorType::GetDamage(float damage_applied, int in_damage_type_idx, float d // Nuke: idiotproof this, no segfault 4 u if ( (storage_idx < 0) || (storage_idx >= AT_NUM_STORAGE_LOCATIONS) ) { Warning(LOCATION, "+Value: for +Load: calculation out of range. Should be between 0 and %i. Read: %i, Skipping calculation.", AT_NUM_STORAGE_LOCATIONS, storage_idx); - storage_idx = 0; } else { damage_applied = storage[storage_idx]; } From b34d74087cba040672c6c4ccf25a593191ff0208 Mon Sep 17 00:00:00 2001 From: John Fernandez Date: Fri, 3 Nov 2023 23:01:45 -0400 Subject: [PATCH 07/10] Actually acquire a subsystem In hud_lock_acquire_current_target, because we didn't need a pointer here, we needed a pointer of a pointer. For coverity 1522999 --- code/hud/hudlock.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/code/hud/hudlock.cpp b/code/hud/hudlock.cpp index aeb7e03a477..44ca6db9d1a 100644 --- a/code/hud/hudlock.cpp +++ b/code/hud/hudlock.cpp @@ -719,7 +719,7 @@ void hud_do_lock_indicator(float frametime) } } -void hud_lock_acquire_current_target(object *target_objp, ship_subsys *target_subsys) +void hud_lock_acquire_current_target(object *target_objp, ship_subsys **target_subsys) { ship *target_shipp=nullptr; int lock_in_range=0; @@ -735,7 +735,7 @@ void hud_lock_acquire_current_target(object *target_objp, ship_subsys *target_su weapon_info* wip = &Weapon_info[swp->secondary_bank_weapons[swp->current_secondary_bank]]; // Reset target subsys in case it isn't needed - if (target_subsys != nullptr) target_subsys = nullptr; + if (*target_subsys != nullptr) *target_subsys = nullptr; // if a large ship, lock to pos closest to center and within range if ( (target_shipp) && (Ship_info[target_shipp->ship_info_index].is_big_or_huge()) ) { @@ -764,7 +764,7 @@ void hud_lock_acquire_current_target(object *target_objp, ship_subsys *target_su lock_dot=vm_vec_dot(&Player_obj->orient.vec.fvec, &vec_to_lock); if ( lock_dot > best_lock_dot ) { best_lock_dot=lock_dot; - target_subsys = ss; + *target_subsys = ss; } } ss = GET_NEXT( ss ); @@ -1073,7 +1073,7 @@ void hud_lock_determine_lock_target(lock_info *lock_slot, weapon_info *wip) } } } else { - hud_lock_acquire_current_target(lock_slot->obj, lock_slot->subsys); + hud_lock_acquire_current_target(lock_slot->obj, &lock_slot->subsys); } } } else { @@ -1124,7 +1124,7 @@ void hud_lock_determine_lock_target(lock_info *lock_slot, weapon_info *wip) } } } else { - hud_lock_acquire_current_target(lock_slot->obj, lock_slot->subsys); + hud_lock_acquire_current_target(lock_slot->obj, &lock_slot->subsys); } } } From f462f74a120a1c832bfced564e448c61e2869b88 Mon Sep 17 00:00:00 2001 From: John Fernandez Date: Fri, 3 Nov 2023 23:19:18 -0400 Subject: [PATCH 08/10] Remove assignment This is just another cleanup pointed out by coverity 1523154 --- code/bmpman/bmpman.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/code/bmpman/bmpman.cpp b/code/bmpman/bmpman.cpp index 3d8480e437a..d691a3a23c7 100644 --- a/code/bmpman/bmpman.cpp +++ b/code/bmpman/bmpman.cpp @@ -2159,7 +2159,8 @@ void bm_lock_ani(int /*handle*/, bitmap_slot *bs, bitmap* /*bmp*/, int bpp, usho // Skip a frame if ((i < nframes - 1) && can_drop_frames) { - frame_data = anim_get_next_raw_buffer(the_anim_instance, 0, flags & BMP_AABITMAP ? 1 : 0, bm->bpp); + // we can just ignore the return since we're skipping the frame. + anim_get_next_raw_buffer(the_anim_instance, 0, flags & BMP_AABITMAP ? 1 : 0, bm->bpp); } } From 61c811ddfb8451d5acb3fed0e79c561ad9d2d0fd Mon Sep 17 00:00:00 2001 From: John Fernandez Date: Fri, 3 Nov 2023 23:18:42 -0400 Subject: [PATCH 09/10] Remove Superfluous Variable This cleans up the code and keeps us from thinking that target_ship_obj is needed. This is a retail issue. Marked by coverity 1320528 --- code/ai/aicode.cpp | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/code/ai/aicode.cpp b/code/ai/aicode.cpp index 527e7956b81..0e08fdcdae9 100644 --- a/code/ai/aicode.cpp +++ b/code/ai/aicode.cpp @@ -14546,7 +14546,6 @@ int aas_1(object *objp, ai_info *aip, vec3d *safe_pos) weapon *weaponp = &Weapons[weapon_objp->instance]; weapon_info *wip = &Weapon_info[weaponp->weapon_info_index]; - object *target_ship_obj = NULL; if (wip->shockwave.speed == 0.0f) { aip->ai_flags.remove(AI::AI_Flags::Avoid_shockwave_weapon); @@ -14565,16 +14564,12 @@ int aas_1(object *objp, ai_info *aip, vec3d *safe_pos) // time in the future, this time based on max lifetime and life left. if (wip->is_locked_homing()) { expected_pos = weaponp->homing_pos; - if (weaponp->homing_object && weaponp->homing_object->type == OBJ_SHIP) { - target_ship_obj = weaponp->homing_object; - } pos_set = 1; if (IS_VEC_NULL(&weaponp->homing_pos)) { pos_set = 0; if (weaponp->target_num != -1) { if (Objects[weaponp->target_num].type == OBJ_SHIP) { - target_ship_obj = &Objects[weaponp->target_num]; - expected_pos = target_ship_obj->pos; + expected_pos = Objects[weaponp->target_num].pos; pos_set = 1; } } From 2fca4e44221242a29412a3de8924d283f7b7f344 Mon Sep 17 00:00:00 2001 From: John Fernandez Date: Sat, 4 Nov 2023 13:53:35 -0400 Subject: [PATCH 10/10] CI unused variable --- code/missionui/missionshipchoice.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/code/missionui/missionshipchoice.cpp b/code/missionui/missionshipchoice.cpp index 72a06872e9d..d508b6c8855 100644 --- a/code/missionui/missionshipchoice.cpp +++ b/code/missionui/missionshipchoice.cpp @@ -2432,7 +2432,7 @@ commit_pressed_status create_wings(bool API_Access) ss_slot_info *ws; wing *wp; - int shipnum, objnum, slot_index; + int shipnum, slot_index; int cleanup_ship_index[MAX_WING_SLOTS]; int i,j,k; @@ -2465,7 +2465,6 @@ commit_pressed_status create_wings(bool API_Access) return commit_pressed_status::PLAYER_NO_WEAPONS; } - objnum = OBJ_INDEX(Player_obj); } else { // We should always update the parse object information, even if the ship is present at start, // because the wing might have more than one wave or scripting functions might need accurate data