Address a bunch of dead store issues found by the static analyzer.

Pretty much all of these fall into one of two categories:

* Variables that are obviously unneeded and in many cases completely unused – probably remnants of old code that was rewritten. These ones were deleted.

* Variables that look like they should be used but aren't. These ones have been suppressed, with a TODO message added as a reminder to investigate them in more detail later.
This commit is contained in:
2024-08-10 12:22:05 -04:00
parent 1d491e3b2a
commit f400a5b7de
12 changed files with 28 additions and 35 deletions

View File

@@ -2404,6 +2404,7 @@ void do_monster_turn() {
&& !acted_yet && get_ran(1,1,1000) < cur_monst->abil[eMonstAbil::DAMAGE2].gen.odds) {
if(target != 6 && dist(cur_monst->cur_loc,targ_space) <= cur_monst->abil[eMonstAbil::DAMAGE2].gen.range) {
acted_yet = monst_breathe(cur_monst,targ_space,cur_monst->abil[eMonstAbil::DAMAGE2]);
(void) acted_yet; // TODO: Is it correct to discard this and make it always true?
had_monst = true;
acted_yet = true;
take_m_ap(4,cur_monst);
@@ -2416,6 +2417,7 @@ void do_monster_turn() {
|| (cur_monst->level > 9))
&& (dist(cur_monst->cur_loc,targ_space) <= 10)) {
acted_yet = monst_cast_mage(cur_monst,target);
(void) acted_yet; // TODO: Is it correct to discard this and make it always true?
had_monst = true;
acted_yet = true;
take_m_ap(5,cur_monst);
@@ -2426,6 +2428,7 @@ void do_monster_turn() {
if((!monst_adjacent(targ_space,i) || (get_ran(1,0,2) < 2) || (cur_monst->level > 9))
&& (dist(cur_monst->cur_loc,targ_space) <= 10)) {
acted_yet = monst_cast_priest(cur_monst,target);
(void) acted_yet; // TODO: Is it correct to discard this and make it always true?
had_monst = true;
acted_yet = true;
take_m_ap(4,cur_monst);
@@ -3285,7 +3288,6 @@ void monst_basic_abil(short m_num, std::pair<eMonstAbil,uAbility> abil, iLiving*
break;
case eMonstAbil::DRAIN_XP:
if(pc_target != nullptr) {
i = univ.get_target_i(*target);
if(pc_target->has_abil_equip(eItemAbil::LIFE_SAVING)) break;
drain_pc(*pc_target, percent(univ.town.monst[m_num].level, abil.second.gen.strength));
}
@@ -3948,7 +3950,7 @@ bool monst_cast_priest(cCreature *caster,short targ) {
case eSpell::BLESS_PARTY: case eSpell::REVIVE_ALL:
play_sound(24);
// TODO: What's r2 for here? Should it be used for Revive All?
r1 = get_ran(2,1,4); r2 = get_ran(3,1,6);
r1 = get_ran(2,1,4); r2 = get_ran(3,1,6); (void) r2;
for(short i = 0; i < univ.town.monst.size(); i++)
if((monst_near(i,caster->cur_loc,8,0)) &&
(caster->attitude == univ.town.monst[i].attitude)) {

View File

@@ -1110,6 +1110,10 @@ void do_sign(short town_num, short which_sign, short sign_type) {
store_sign_mode = sign_type;
pict.setPict(univ.scenario.ter_types[sign_type].picture);
// TODO: Why is town_num unused?
// Seems like it could cause the wrong sign to show sometimes,
// like when you're in one outdoor section viewing a sign in
// an adjacent section
if(town_num >= 200) {
town_num -= 200;
sign_text = univ.out->sign_locs[which_sign].text;
@@ -1117,6 +1121,7 @@ void do_sign(short town_num, short which_sign, short sign_type) {
else {
sign_text = univ.town->sign_locs[which_sign].text;
}
(void) town_num;
sign->getControl("sign").setText(sign_text);
sign.show();

View File

@@ -680,7 +680,7 @@ void draw_terrain(short mode) {
location sector_p_in,view_loc;
char can_draw;
ter_num_t spec_terrain;
bool off_terrain = false,draw_frills = true;
bool draw_frills = true;
bool frills_on = get_bool_pref("DrawTerrainShoreFrills", true);
if(overall_mode == MODE_TALKING || overall_mode == MODE_SHOPPING || overall_mode == MODE_STARTUP)
@@ -752,7 +752,6 @@ void draw_terrain(short mode) {
where_draw = (is_out()) ? univ.party.out_loc : center;
where_draw.x += q - 4;
where_draw.y += r - 4;
off_terrain = false;
if (where_draw.x < 0 || where_draw.y < 0 || where_draw.x >= max_dim_x || where_draw.y >= max_dim_y)
continue;
draw_frills = true;

View File

@@ -62,7 +62,6 @@ void draw_one_terrain_spot (short i,short j,short terrain_to_draw) {
rectangle where_draw;
rectangle source_rect;
std::shared_ptr<const sf::Texture> source_gworld;
short anim_type = 0;
location l;
l.x = i; l.y = j;
@@ -82,11 +81,9 @@ void draw_one_terrain_spot (short i,short j,short terrain_to_draw) {
source_gworld = &ResMgr::graphics.get("ter" + std::to_string(1 + which_sheet));
terrain_to_draw %= 50;
source_rect = calc_rect(terrain_to_draw % 10, terrain_to_draw / 10);
anim_type = -1;
}
else if(univ.scenario.ter_types[terrain_to_draw].picture >= 2000) { // custom
graf_pos_ref(source_gworld, source_rect) = spec_scen_g.find_graphic(univ.scenario.ter_types[terrain_to_draw].picture - 2000 + (anim_ticks % 4));
anim_type = 0;
}
else if(univ.scenario.ter_types[terrain_to_draw].picture >= 1000) { // custom
graf_pos_ref(source_gworld, source_rect) = spec_scen_g.find_graphic(univ.scenario.ter_types[terrain_to_draw].picture - 1000);
@@ -95,7 +92,6 @@ void draw_one_terrain_spot (short i,short j,short terrain_to_draw) {
source_gworld = &ResMgr::graphics.get("teranim");
terrain_to_draw = univ.scenario.ter_types[terrain_to_draw].picture;
source_rect = calc_rect(4 * ((terrain_to_draw - 960) / 5) + (anim_ticks % 4),(terrain_to_draw - 960) % 5);
anim_type = 0;
}
else {
terrain_to_draw = univ.scenario.ter_types[terrain_to_draw].picture;
@@ -103,7 +99,6 @@ void draw_one_terrain_spot (short i,short j,short terrain_to_draw) {
source_gworld = &ResMgr::graphics.get("ter" + std::to_string(1 + which_sheet));
terrain_to_draw %= 50;
source_rect = calc_rect(terrain_to_draw % 10, terrain_to_draw / 10);
anim_type = -1;
}
rect_draw_some_item(*source_gworld, source_rect, terrain_screen_gworld, where_draw);
@@ -205,11 +200,7 @@ void draw_monsters() {
}
void play_see_monster_str(unsigned short m, location monst_loc) {
short pic, spec;
ePicType type;
pic = univ.scenario.scen_monsters[m].picture_num;
type = get_monst_pictype(m);
spec = univ.scenario.scen_monsters[m].see_spec;
short spec = univ.scenario.scen_monsters[m].see_spec;
// Then run the special, if any
if(spec > -1){
queue_special(eSpecCtx::SEE_MONST, eSpecCtxType::SCEN, spec, monst_loc);

View File

@@ -862,11 +862,7 @@ void change_cursor(location where_curs) {
void move_sound(ter_num_t ter,short step){
static bool on_swamp = false;
short pic;
eTerSpec spec;
pic = univ.scenario.ter_types[ter].picture;
spec = univ.scenario.ter_types[ter].special;
eTerSpec spec = univ.scenario.ter_types[ter].special;
eStepSnd snd = univ.scenario.ter_types[ter].step_sound;
// if on swamp don't play squish sound : BoE legacy behavior, can be removed safely

View File

@@ -155,7 +155,6 @@ void init_menubar() {
i = 0;
for(eMenu opt : help_choices)
setMenuCallback([help_menu itemAtIndex: i++], handler, @selector(menuChoice:), int(opt));
i = 0;
setMenuCallback([mage_spells_menu itemAtIndex: 0], handler, @selector(menuChoice:), int(eMenu::ABOUT_MAGE));
setMenuCallback([priest_spells_menu itemAtIndex: 0], handler, @selector(menuChoice:), int(eMenu::ABOUT_PRIEST));

View File

@@ -258,7 +258,6 @@ void do_monsters() {
if(overall_mode == MODE_OUTDOORS) {
for(short i = 0; i < 10; i++)
if(univ.party.out_c[i].exists) {
acted_yet = false;
l1 = univ.party.out_c[i].m_loc;
l2 = univ.party.out_loc;
@@ -268,6 +267,7 @@ void do_monsters() {
else acted_yet = seek_party(i,l1,l2);
}
}
(void) acted_yet; // TODO: Why is acted_yet ignored?
}
bool monst_hate_spot(short which_m,location *good_loc) {

View File

@@ -616,6 +616,7 @@ void do_mage_spell(short pc_num,eSpell spell_num,bool freebie) {
break;
case eSpell::SUMMON_WEAK:
store = level / 5 + adj / 3 + get_ran(1,0,2);
(void) store; // TODO: Why is this calculation just discarded?
r1 = get_summon_monster(1); ////
if(r1 < 0) break;
if(!freebie)
@@ -627,6 +628,7 @@ void do_mage_spell(short pc_num,eSpell spell_num,bool freebie) {
break;
case eSpell::SUMMON:
store = level / 7 + adj / 3 + get_ran(1,0,1);
(void) store; // TODO: Why is this calculation just discarded?
r1 = get_summon_monster(2); ////
if(r1 < 0) break;
if(!freebie)
@@ -645,6 +647,7 @@ void do_mage_spell(short pc_num,eSpell spell_num,bool freebie) {
break;
case eSpell::SUMMON_MAJOR:
store = level / 10 + adj / 3 + get_ran(1,0,1);
(void) store; // TODO: Why is this calculation just discarded?
r1 = get_summon_monster(3); ////
if(r1 < 0) break;
if(!freebie)
@@ -1332,6 +1335,7 @@ void cast_town_spell(location where) {
}
else {
store = get_ran(1,0,1);
(void) store; // TODO: Why does it even do this?
play_sound(41);
add_string_to_buf(" Didn't work.");
}
@@ -2093,6 +2097,7 @@ void do_alchemy() {
if(r1 < fail_chance[univ.party[pc_num].skill(eSkill::ALCHEMY) - alch_difficulty[which_p]]) {
add_string_to_buf("Alchemy: Failed.");
r1 = get_ran(1,0,1);
(void) r1; // TODO: Why does it even do this?
play_sound(41 );
}
else {
@@ -2130,12 +2135,9 @@ static bool alch_choice_event_filter(cDialog& me, std::string item_hit, eKeyMod)
eAlchemy alch_choice(short pc_num) {
short difficulty[20] = {1,1,1,3,3, 4,5,5,7,9, 9,10,12,12,9, 14,19,10,16,20};
short store_alchemy_pc;
set_cursor(sword_curs);
store_alchemy_pc = pc_num;
cDialog chooseAlchemy(*ResMgr::dialogs.get("pick-potion"));
chooseAlchemy.attachClickHandlers(alch_choice_event_filter, {"cancel", "help"});
for(short i = 0; i < 20; i++) {
@@ -2506,6 +2508,7 @@ void kill_pc(cPlayer& which_pc,eMainStatus type) {
for(cItem& item : which_pc.items)
if(item.variety != eItemType::NO_ITEM) {
dummy = place_item(item,item_loc);
(void) dummy;
item.variety = eItemType::NO_ITEM;
}
if(type == eMainStatus::DEAD || type == eMainStatus::DUST)

View File

@@ -143,7 +143,7 @@ bool handle_wandering_specials(short mode) {
// sets forced to true if definitely can enter
bool check_special_terrain(location where_check,eSpecCtx mode,cPlayer& which_pc,bool *forced) {
ter_num_t ter;
short r1,door_pc,pic_type = 0,ter_pic = 0;
short r1,door_pc,pic_type = 0;
eTerSpec ter_special;
std::string choice;
int ter_flag1,ter_flag2,ter_flag3;
@@ -178,7 +178,6 @@ bool check_special_terrain(location where_check,eSpecCtx mode,cPlayer& which_pc,
ter_flag1 = univ.scenario.ter_types[ter].flag1;
ter_flag2 = univ.scenario.ter_types[ter].flag2;
ter_flag3 = univ.scenario.ter_types[ter].flag3;
ter_pic = univ.scenario.ter_types[ter].picture;
// TODO: Why not support conveyors outdoors, too?
if(mode != eSpecCtx::OUT_MOVE && ter_special == eTerSpec::CONVEYOR) {
@@ -584,6 +583,8 @@ void use_item(short pc,short item) {
eItemAbil abil = item_rec.ability;
bool inept_ok = !item_rec.use_magic();
level = univ.party[pc].items[item].item_level;
(void) level; // TODO: Is it correct to never use the level?
// Maybe it is, since abilities have their own level?
if(is_out())
user_loc = univ.party.out_loc;
@@ -1136,7 +1137,7 @@ void use_item(short pc,short item) {
add_string_to_buf(" Summon failed.");
break;
case eItemAbil::MASS_SUMMONING:
r1 = get_ran(str,1,4); // TODO: This value was never used, so why is it here?
r1 = get_ran(str,1,4); (void) r1; // TODO: This value was never used, so why is it here?
r1 = get_ran(1,3,5);
for(short i = 0; i < r1; i++)
if(!summon_monster(the_item.abil_data.value,user_loc,r1,eAttitude::FRIENDLY,true))
@@ -1723,6 +1724,7 @@ void push_things() {
univ.party.town_loc = l;
update_explored(l);
ter = univ.town->terrain(univ.party.town_loc.x,univ.party.town_loc.y);
(void) ter; // Though it's never read currently, it at least keeps things consistent
draw_map(true);
if(univ.town.is_barrel(univ.party.town_loc.x,univ.party.town_loc.y)) {
univ.town.set_barrel(univ.party.town_loc.x,univ.party.town_loc.y,false);

View File

@@ -1051,7 +1051,6 @@ void print_buf () {
long ctrl_val;
short line_to_print;
long start_print_point;
bool end_loop = false;
rectangle store_text_rect,dest_rect,erase_rect = {2,2,136,255};
text_area_gworld.setActive(false);
@@ -1079,7 +1078,6 @@ void print_buf () {
}
if((num_lines_printed == LINES_IN_TEXT_WIN - 1) && (printing_long)) {
end_loop = false;
line_to_print= buf_pointer;
}

View File

@@ -72,7 +72,7 @@ void force_town_enter(short which_town,location where_start) {
//short entry_dir; // if 9, go to forced
void start_town_mode(short which_town, short entry_dir) {
short town_number;
short at_which_save_slot,former_town;
short former_town;
bool monsters_loaded = false,town_toast = false;
location loc;
bool play_town_sound = false;
@@ -143,8 +143,6 @@ void start_town_mode(short which_town, short entry_dir) {
univ.town.monst.which_town = town_number;
univ.town.monst.hostile = false;
at_which_save_slot = univ.party.at_which_save_slot;
for(auto& pop : univ.party.creature_save)
if(town_number == pop.which_town) {
univ.town.monst = pop;
@@ -1306,12 +1304,10 @@ void draw_map(bool need_refresh) {
rectangle area_to_draw_from,area_to_draw_on = {29,47,269,287};
ter_num_t what_ter;
bool draw_surroundings = false,expl;
bool expl;
short total_size = 48; // if full redraw, use this to figure out everything
rectangle custom_from;
draw_surroundings = true;
town_map_adj.x = 0;
town_map_adj.y = 0;