str("") is unsafe on its own for clearing stream
This commit is contained in:
@@ -88,7 +88,7 @@ void cPictChoice::fillPage(){
|
||||
dlg[sout.str()].show();
|
||||
if(page * per_page + i == cur)
|
||||
group.setSelected(sout.str());
|
||||
sout.str("");
|
||||
clear_sstr(sout);
|
||||
sout << "pic" << i + 1;
|
||||
cPict& pic = dynamic_cast<cPict&>(dlg[sout.str()]);
|
||||
if(page * per_page + i < picts.size()){
|
||||
|
@@ -98,7 +98,7 @@ void cStringChoice::fillPage(){
|
||||
sout << "led" << i + 1;
|
||||
std::string led_id = sout.str(), text_id;
|
||||
if(editable) {
|
||||
sout.str("");
|
||||
clear_sstr(sout);
|
||||
sout << "edit" << i + 1;
|
||||
text_id = sout.str();
|
||||
} else text_id = led_id;
|
||||
|
@@ -2122,8 +2122,7 @@ void debug_print_location() {
|
||||
short y = univ.party.out_loc.y;
|
||||
sout << "Debug: You're outside in sec x " << univ.party.outdoor_corner.x << ", y " << univ.party.outdoor_corner.y << '\n';
|
||||
add_string_to_buf(sout.str());
|
||||
sout.str("");
|
||||
sout.seekp(0);
|
||||
clear_sstr(sout);
|
||||
sout << " local x " << x << ", y " << y;
|
||||
x += 48 * univ.party.outdoor_corner.x;
|
||||
y += 48 * univ.party.outdoor_corner.y;
|
||||
|
@@ -1689,14 +1689,13 @@ class cChooseScenario {
|
||||
short page = n - 1;
|
||||
stk.setPage(n);
|
||||
for(short i = 0; i < 3; i++) {
|
||||
sout.clear();
|
||||
sout.str("");
|
||||
clear_sstr(sout);
|
||||
sout << i + 1;
|
||||
std::string n = sout.str();
|
||||
if(scen_headers.size() > (page * 3 + i)) {
|
||||
me["pic" + n].show();
|
||||
dynamic_cast<cPict&>(me["pic" + n]).setPict(scen_headers[page * 3 + i].intro_pic);
|
||||
sout.str("");
|
||||
clear_sstr(sout);
|
||||
sout << scen_headers[page * 3 + i].name;
|
||||
sout << " v" << int(scen_headers[page * 3 + i].ver[0]);
|
||||
sout << '.' << int(scen_headers[page * 3 + i].ver[1]);
|
||||
|
@@ -345,14 +345,14 @@ static void display_pc_info(cDialog& me, const short pc_num) {
|
||||
|
||||
to_draw << pc.name << " is carrying " << pc.cur_weight() << " stones out of " << pc.max_weight() << '.';
|
||||
me["weight"].setText(to_draw.str());
|
||||
to_draw.str("");
|
||||
clear_sstr(to_draw);
|
||||
|
||||
to_draw << pc.cur_health << " out of " << pc.max_health << '.';
|
||||
me["hp"].setText(to_draw.str());
|
||||
to_draw.str("");
|
||||
clear_sstr(to_draw);
|
||||
to_draw << pc.cur_sp << " out of " << pc.max_sp << '.';
|
||||
me["sp"].setText(to_draw.str());
|
||||
to_draw.str("");
|
||||
clear_sstr(to_draw);
|
||||
|
||||
for(short i = 0; i < 19; i++) {
|
||||
eSkill skill = eSkill(i);
|
||||
@@ -360,7 +360,7 @@ static void display_pc_info(cDialog& me, const short pc_num) {
|
||||
to_draw << pc.skills[skill];
|
||||
if(bonus > 0) to_draw << '+' << bonus;
|
||||
me[boost::lexical_cast<std::string>(skill)].setText(to_draw.str());
|
||||
to_draw.str("");
|
||||
clear_sstr(to_draw);
|
||||
}
|
||||
me["encumb"].setTextToNum(pc.armor_encumbrance());
|
||||
me["name"].setText(pc.name);
|
||||
@@ -407,10 +407,10 @@ static void display_pc_info(cDialog& me, const short pc_num) {
|
||||
to_draw << "Penalty to hit: %" << hit_adj + 5 * weap1->bonus;
|
||||
else to_draw << "Bonus to hit: +%" << hit_adj + 5 * weap1->bonus;
|
||||
me["weap1a"].setText(to_draw.str());
|
||||
to_draw.str("");
|
||||
clear_sstr(to_draw);
|
||||
to_draw << "Damage: (1-" << weap1->item_level << ") + " << dam_adj + weap1->bonus;
|
||||
me["weap1b"].setText(to_draw.str());
|
||||
to_draw.str("");
|
||||
clear_sstr(to_draw);
|
||||
}
|
||||
}
|
||||
if(weap2) {
|
||||
@@ -421,10 +421,10 @@ static void display_pc_info(cDialog& me, const short pc_num) {
|
||||
to_draw << "Penalty to hit: %" << hit_adj + 5 * weap2->bonus;
|
||||
else to_draw << "Bonus to hit: +%" << hit_adj + 5 * weap2->bonus;
|
||||
me["weap2a"].setText(to_draw.str());
|
||||
to_draw.str("");
|
||||
clear_sstr(to_draw);
|
||||
to_draw << "Damage: (1-" << weap2->item_level << ") + " << dam_adj + weap2->bonus;
|
||||
me["weap2b"].setText(to_draw.str());
|
||||
to_draw.str("");
|
||||
clear_sstr(to_draw);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -855,7 +855,7 @@ void draw_shop_graphics(bool item_pressed, bool item_help_pressed, rectangle cli
|
||||
}
|
||||
|
||||
// Finally, cost info and help strs
|
||||
title.str("");
|
||||
clear_sstr(title);
|
||||
title << "Prices here are " << cost_strs[active_shop.getCostAdjust()] << '.';
|
||||
style.pointSize = 10;
|
||||
style.lineHeight = 12;
|
||||
|
@@ -1100,7 +1100,7 @@ void do_priest_spell(short pc_num,eSpell spell_num,bool freebie) {
|
||||
add_string_to_buf(" You absorb damage.");
|
||||
sout << " healed " << univ.party[target].cur_health - store_victim_health << '.';
|
||||
add_string_to_buf(sout.str());
|
||||
sout.str("");
|
||||
clear_sstr(sout);
|
||||
sout << univ.party[pc_num].name << " takes " << store_caster_health - univ.party[pc_num].cur_health << '.';
|
||||
} else if(spell_num == eSpell::REVIVE) {
|
||||
sout << " healed.";
|
||||
@@ -1470,11 +1470,11 @@ void do_mindduel(short pc_num,cCreature *monst) {
|
||||
balance++;
|
||||
if(univ.party[pc_num].cur_sp == 0) {
|
||||
univ.party[pc_num].status[eStatus::DUMB] += 2;
|
||||
sout.str("");
|
||||
clear_sstr(sout);
|
||||
sout << " " << univ.party[pc_num].name << " is dumbfounded.";
|
||||
add_string_to_buf(sout.str(), 4);
|
||||
if(univ.party[pc_num].status[eStatus::DUMB] > 7) {
|
||||
sout.str("");
|
||||
clear_sstr(sout);
|
||||
sout << " " << univ.party[pc_num].name << " is killed!";
|
||||
add_string_to_buf(sout.str(), 4);
|
||||
kill_pc(univ.party[pc_num],eMainStatus::DEAD);
|
||||
|
@@ -143,7 +143,7 @@ void put_pc_screen() {
|
||||
|
||||
to_draw_rect = pc_buttons[i][PCBTN_HP];
|
||||
to_draw_rect.right += 20;
|
||||
sout.str("");
|
||||
clear_sstr(sout);
|
||||
switch(univ.party[i].main_status) {
|
||||
case eMainStatus::ALIVE:
|
||||
if(univ.party[i].cur_health == univ.party[i].max_health)
|
||||
@@ -249,7 +249,7 @@ void put_item_screen(eItemWinMode screen_num) {
|
||||
|
||||
default: // on an items page
|
||||
pc = screen_num;
|
||||
sout.str("");
|
||||
clear_sstr(sout);
|
||||
sout << univ.party[pc].name << " inventory:";
|
||||
win_draw_string(item_stats_gworld(),upper_frame_rect,sout.str(),eTextMode::WRAP,style);
|
||||
break;
|
||||
@@ -303,7 +303,7 @@ void put_item_screen(eItemWinMode screen_num) {
|
||||
|
||||
for(short i = 0; i < LINES_IN_ITEM_WIN; i++) {
|
||||
i_num = i + item_offset;
|
||||
sout.str("");
|
||||
clear_sstr(sout);
|
||||
sout << i_num + 1 << '.';
|
||||
win_draw_string(item_stats_gworld(),item_buttons[i][ITEMBTN_NAME],sout.str(),eTextMode::WRAP,style);
|
||||
|
||||
@@ -325,7 +325,7 @@ void put_item_screen(eItemWinMode screen_num) {
|
||||
else style.colour = Colours::BLUE;
|
||||
} else style.colour = Colours::BLACK;
|
||||
|
||||
sout.str("");
|
||||
clear_sstr(sout);
|
||||
|
||||
if(item.ident)
|
||||
sout << item.full_name << ' ';
|
||||
|
@@ -11,6 +11,7 @@
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
typedef unsigned short mon_num_t;
|
||||
typedef signed short miss_num_t;
|
||||
@@ -50,6 +51,12 @@ inline std::string bool_to_str(bool b) {
|
||||
return b ? "true" : "false";
|
||||
}
|
||||
|
||||
inline void clear_sstr(std::ostringstream& sstr) {
|
||||
sstr.clear();
|
||||
sstr.str("");
|
||||
sstr.seekp(0);
|
||||
}
|
||||
|
||||
inline void LOG(std::string line) {
|
||||
std::cout << line << std::endl;
|
||||
}
|
||||
|
@@ -799,7 +799,7 @@ void display_party() {
|
||||
win_draw_string(mainPtr(),dest_rect,to_draw.str(),eTextMode::WRAP,style);
|
||||
dest_rect = pc_race_rect;
|
||||
dest_rect.offset(0,-14);
|
||||
to_draw.str("");
|
||||
clear_sstr(to_draw);
|
||||
to_draw << " Food: " << univ.party.food;
|
||||
win_draw_string(mainPtr(),dest_rect,to_draw.str(),eTextMode::WRAP,style);
|
||||
}
|
||||
|
@@ -2447,7 +2447,7 @@ void set_up_main_screen() {
|
||||
set_lb(-1,LB_TEXT,LB_EDIT_OUT,"Edit Outdoor Terrain");
|
||||
set_lb(-1,LB_TEXT,LB_NO_ACTION,"",0);
|
||||
set_lb(-1,LB_TEXT,LB_NO_ACTION,"Town/Dungeon Options");
|
||||
strb.str("");
|
||||
clear_sstr(strb);
|
||||
strb << " Town " << cur_town << ": " << town->name;
|
||||
set_lb(-1,LB_TEXT,LB_NO_ACTION, strb.str());
|
||||
set_lb(-1,LB_TEXT,LB_LOAD_TOWN,"Load Another Town");
|
||||
|
@@ -646,7 +646,7 @@ static void put_monst_info_in_dlog(cDialog& me, cMonster& monst, mon_num_t which
|
||||
me["pic"].setTextToNum(monst.picture_num);
|
||||
strb << "Width = " << int(monst.x_width);
|
||||
me["w"].setText(strb.str());
|
||||
strb.str("");
|
||||
clear_sstr(strb);
|
||||
strb << "Height = " << int(monst.y_width);
|
||||
me["h"].setText(strb.str());
|
||||
me["level"].setTextToNum(monst.level);
|
||||
@@ -704,7 +704,7 @@ static void put_monst_info_in_dlog(cDialog& me, cMonster& monst, mon_num_t which
|
||||
case 122: summoned_by.push_back(eSpell::SUMMON_GUARDIAN); break;
|
||||
}
|
||||
|
||||
strb.str("");
|
||||
clear_sstr(strb);
|
||||
bool first = true;
|
||||
if(summoned_by.empty())
|
||||
strb << "None";
|
||||
@@ -755,7 +755,7 @@ static bool check_monst_pic(cDialog& me, std::string id, bool losing, cMonster&
|
||||
std::ostringstream strb;
|
||||
strb << "Width = " << int(monst.x_width);
|
||||
me["w"].setText(strb.str());
|
||||
strb.str("");
|
||||
clear_sstr(strb);
|
||||
strb << "Height = " << int(monst.y_width);
|
||||
me["h"].setText(strb.str());
|
||||
}
|
||||
|
@@ -609,7 +609,7 @@ void writeMonstersToXml(ticpp::Printer&& data, cScenario& scenario) {
|
||||
if(monst.guard) data.PushElement("guard");
|
||||
for(auto& p : monst.abil) {
|
||||
if(p.first == eMonstAbil::NO_ABIL || !p.second.active) continue;
|
||||
str.str("");
|
||||
clear_sstr(str);
|
||||
eMonstAbil abil = p.first;
|
||||
uAbility& param = p.second;
|
||||
switch(getMonstAbilCategory(abil)) {
|
||||
|
@@ -1378,14 +1378,14 @@ void place_location() {
|
||||
TextStyle style;
|
||||
style.lineHeight = 12;
|
||||
win_draw_string(mainPtr(), draw_rect, sout.str(), eTextMode::LEFT_TOP, style);
|
||||
sout.str("");
|
||||
clear_sstr(sout);
|
||||
|
||||
moveTo = location(260 ,terrain_rects[255].top + 18);
|
||||
draw_rect = text_rect;
|
||||
draw_rect.offset(moveTo);
|
||||
sout << current_terrain_type;
|
||||
win_draw_string(mainPtr(), draw_rect, sout.str(), eTextMode::LEFT_TOP, style);
|
||||
sout.str("");
|
||||
clear_sstr(sout);
|
||||
|
||||
if(overall_mode < MODE_MAIN_SCREEN) {
|
||||
moveTo = location(5,terrain_rects[255].bottom + 121);
|
||||
|
@@ -1463,7 +1463,7 @@ static void put_out_loc_in_dlog(cDialog& me, location cur_loc, cScenario& scenar
|
||||
std::ostringstream str;
|
||||
str << "X = " << cur_loc.x;
|
||||
me["x"].setText(str.str());
|
||||
str.str("");
|
||||
clear_sstr(str);
|
||||
str << "Y = " << cur_loc.y;
|
||||
me["y"].setText(str.str());
|
||||
me["title"].setText(scenario.outdoors[cur_loc.x][cur_loc.y]->name);
|
||||
|
Reference in New Issue
Block a user