diff --git a/src/dialogxml/dialogs/dialog.cpp b/src/dialogxml/dialogs/dialog.cpp index db518e71..b58fdc5c 100644 --- a/src/dialogxml/dialogs/dialog.cpp +++ b/src/dialogxml/dialogs/dialog.cpp @@ -552,7 +552,8 @@ void cDialog::run(std::function onopen){ win.close(); #endif win.create(sf::VideoMode(winRect.width(), winRect.height()), "Dialog", sf::Style::Titlebar); - win.setPosition({parentPos.x + int(parentSz.x - winRect.width()) / 2, parentPos.y + int(parentSz.y - winRect.height()) / 2}); + // ASAN overflow + win.setPosition({parentPos.x + (int(parentSz.x) - winRect.width()) / 2, parentPos.y + (int(parentSz.y) - winRect.height()) / 2}); draw(); makeFrontWindow(parent ? parent-> win : mainPtr); makeFrontWindow(win); diff --git a/src/game/boe.dlgutil.cpp b/src/game/boe.dlgutil.cpp index a41be617..687eb059 100644 --- a/src/game/boe.dlgutil.cpp +++ b/src/game/boe.dlgutil.cpp @@ -548,7 +548,8 @@ void set_up_shop_array() { break; } } - shop_sbar->setMaximum(shop_array.size() - 8); + // ASAN undefined behaviour + shop_sbar->setMaximum(long(shop_array.size()) - 8); } void start_talk_mode(short m_num,short personality,mon_num_t monst_type,short store_face_pic) { diff --git a/src/game/boe.infodlg.cpp b/src/game/boe.infodlg.cpp index ba79a8d4..7b7e0890 100644 --- a/src/game/boe.infodlg.cpp +++ b/src/game/boe.infodlg.cpp @@ -701,15 +701,25 @@ void cStringRecorder::operator()(cDialog& me) { switch(type) { case NOTE_SCEN: str1 = univ.scenario.spec_strs[label1]; - str2 = univ.scenario.spec_strs[label2]; + if (label2>=univ.scenario.spec_strs.size()) + showError("cStringRecorder(): bad label 2."); + else + str2 = univ.scenario.spec_strs[label2]; break; case NOTE_TOWN: str1 = univ.town->spec_strs[label1]; - str2 = univ.town->spec_strs[label2]; + if (label2>=univ.town->spec_strs.size()) + showError("cStringRecorder(): bad label 2."); + else + str2 = univ.town->spec_strs[label2]; break; case NOTE_OUT: str1 = univ.scenario.outdoors[label1b][label2b]->spec_strs[label1]; - str2 = univ.scenario.outdoors[label1b][label2b]->spec_strs[label2]; + // memory problem, ie. called with label=65535(-1) + if (label2>=univ.scenario.outdoors[label1b][label2b]->spec_strs.size()) + showError("cStringRecorder(): bad label 2."); + else + str2 = univ.scenario.outdoors[label1b][label2b]->spec_strs[label2]; break; } if(univ.party.record(type, str1, location)) diff --git a/src/game/boe.items.cpp b/src/game/boe.items.cpp index 445a06f0..3c9a48f2 100644 --- a/src/game/boe.items.cpp +++ b/src/game/boe.items.cpp @@ -387,7 +387,8 @@ static void put_item_graphics(cDialog& me, size_t& first_item_shown, short& curr if(first_item_shown == 0) me["up"].hide(); else me["up"].show(); - if(first_item_shown > item_array.size() - 7 || + // ASAN undefined behaviour, ie. item_array.size can be less than 7 + if(first_item_shown+7 > item_array.size() || item_array.size() <= 8) me["down"].hide(); else me["down"].show(); diff --git a/src/scenario/scenario.cpp b/src/scenario/scenario.cpp index b821bd2c..a202e644 100644 --- a/src/scenario/scenario.cpp +++ b/src/scenario/scenario.cpp @@ -66,6 +66,8 @@ cScenario::cScenario() { bg_fight = 4; bg_town = 13; bg_dungeon = 9; + // ASAN used but unset + is_legacy = false; for(short i = 0; i < town_mods.size(); i++) { town_mods[i].spec = -1; } diff --git a/src/tools/vector2d.hpp b/src/tools/vector2d.hpp index f31c865f..6cc4f96f 100644 --- a/src/tools/vector2d.hpp +++ b/src/tools/vector2d.hpp @@ -152,7 +152,8 @@ public: size_t old_w = w, old_h = h; w = width; h = height; data.resize(w * h); - if(old_w < width) { + // ASAN undefined behaviour if old_h==0, y=old_h-1 is ... + if(old_w < width && old_h) { size_t dx = width - old_w; for(int y = old_h - 1; y > 0; y--) { std::move_backward(data.begin() + old_w * y, data.begin() + old_w * (y + 1), data.begin() + w * (y + 1) - dx); diff --git a/src/universe/creature.cpp b/src/universe/creature.cpp index 01f583d1..d2bc0b07 100644 --- a/src/universe/creature.cpp +++ b/src/universe/creature.cpp @@ -20,6 +20,8 @@ const short cCreature::charm_odds[21] = {90,90,85,80,78, 75,73,60,40,30, 20,10,4 cCreature::cCreature() { attitude = eAttitude::DOCILE; cur_loc.x = cur_loc.y = targ_loc.x = targ_loc.y = 80; + // ASAN party_summoned writed but unset + party_summoned = false; } cCreature::cCreature(int num) : cCreature() { diff --git a/src/universe/population.hpp b/src/universe/population.hpp index 1c2f2bcd..18262fce 100644 --- a/src/universe/population.hpp +++ b/src/universe/population.hpp @@ -32,7 +32,8 @@ public: void clear() {dudes.clear();} cCreature& operator[](size_t n); const cCreature& operator[](size_t n) const; - cPopulation() : which_town(200) {} + // ASAN hostile copied but unset + cPopulation() : which_town(200), hostile(false) {} std::vector::iterator begin() {return dudes.begin();} std::vector::iterator end() {return dudes.end();} // Apparently Visual Studio needs this to work