Asan: correct some undefined, ... problems

This commit is contained in:
Laurent Alonso(fr)
2020-05-16 15:15:38 +02:00
committed by Celtic Minstrel
parent b6c5552ac0
commit 9f802b3fcf
8 changed files with 27 additions and 8 deletions

View File

@@ -552,7 +552,8 @@ void cDialog::run(std::function<void(cDialog&)> 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);

View File

@@ -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) {

View File

@@ -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))

View File

@@ -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();

View File

@@ -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;
}

View File

@@ -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);

View File

@@ -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() {

View File

@@ -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<cCreature>::iterator begin() {return dudes.begin();}
std::vector<cCreature>::iterator end() {return dudes.end();}
// Apparently Visual Studio needs this to work