From a202918d5761b5fad90a8d083dec24d831d4a264 Mon Sep 17 00:00:00 2001 From: Celtic Minstrel Date: Sat, 10 Aug 2024 11:56:51 -0400 Subject: [PATCH] Address UB warnings found by the static analyzer --- src/game/boe.actions.cpp | 4 ++-- src/game/boe.combat.cpp | 2 +- src/game/boe.specials.cpp | 4 ++-- src/game/boe.text.cpp | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/game/boe.actions.cpp b/src/game/boe.actions.cpp index 84eb14ab..381f1681 100644 --- a/src/game/boe.actions.cpp +++ b/src/game/boe.actions.cpp @@ -2744,7 +2744,7 @@ location get_cur_direction(location the_point) { static eDirection find_waterfall(short x, short y, short mode){ // If more than one waterfall adjacent, randomly selects - bool to_dir[8]; + std::bitset<8> to_dir; for(eDirection i = DIR_N; i < DIR_HERE; i++){ if(mode == 0){ eTerSpec spec = univ.scenario.ter_types[univ.town->terrain(x + dir_x_dif[i],y + dir_y_dif[i])].special; @@ -2757,7 +2757,7 @@ static eDirection find_waterfall(short x, short y, short mode){ } } short count = 0; - for(int i = 0; i < 8; i++) + for(int i = DIR_N; i < DIR_HERE; i++) count += to_dir[i]; if(count > 0) count = get_ran(1,1,count); else return DIR_HERE; diff --git a/src/game/boe.combat.cpp b/src/game/boe.combat.cpp index 4edf387e..3121f7ab 100644 --- a/src/game/boe.combat.cpp +++ b/src/game/boe.combat.cpp @@ -1023,7 +1023,7 @@ void do_combat_cast(location target) { CLOUD_STINK,CLOUD_STINK, WALL_ICE,WALL_ICE,WALL_BLADES, }; - mon_num_t summon; + mon_num_t summon = 0; iLiving* victim; cPlayer& caster = univ.current_pc(); bool allow_obstructed = false, allow_antimagic = false; diff --git a/src/game/boe.specials.cpp b/src/game/boe.specials.cpp index 3efc3a9b..fb141064 100644 --- a/src/game/boe.specials.cpp +++ b/src/game/boe.specials.cpp @@ -3554,7 +3554,7 @@ void ifthen_spec(const runtime_state& ctx) { ctx.next_spec = spec.ex1b; else if(dynamic_cast(¤t_pc_picked_in_spec_enc(ctx))) { int pc = univ.get_target_i(current_pc_picked_in_spec_enc(ctx)); - eMainStatus stat; + eMainStatus stat = eMainStatus::ALIVE; switch(spec.ex1a) { case 0: stat = eMainStatus::DEAD; @@ -4570,7 +4570,7 @@ void handle_message(const runtime_state& ctx, const std::string& title, pic_num_ } void get_strs(std::string& str1,std::string& str2,eSpecCtxType cur_type,short which_str1,short which_str2) { - size_t num_strs; + size_t num_strs = 0; if(cur_type == eSpecCtxType::SCEN) num_strs = univ.scenario.spec_strs.size(); else if(cur_type == eSpecCtxType::OUTDOOR) diff --git a/src/game/boe.text.cpp b/src/game/boe.text.cpp index 2b3fc4b4..0b9df93f 100644 --- a/src/game/boe.text.cpp +++ b/src/game/boe.text.cpp @@ -915,7 +915,7 @@ void print_nums(short a,short b,short c) { } short print_terrain(location space) { - ter_num_t which_terrain; + ter_num_t which_terrain = 0; if(overall_mode == MODE_LOOK_OUTDOORS) { which_terrain = univ.out[space.x][space.y];