str("") is unsafe on its own for clearing stream

This commit is contained in:
2025-04-20 19:21:02 -05:00
parent a2f4c8a903
commit 58107f1856
15 changed files with 37 additions and 32 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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