From 1ce6c6cc94d5e77d67202b731c641a2411584548 Mon Sep 17 00:00:00 2001 From: Celtic Minstrel Date: Mon, 14 Apr 2014 15:07:12 -0400 Subject: [PATCH] Fixed crash when getting items and some other improper use of std::ostringstream --- osx/boe.items.cpp | 24 +++++++++++------------- osx/boe.text.cpp | 4 ++-- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/osx/boe.items.cpp b/osx/boe.items.cpp index c8f1a99f4..f61459a7d 100644 --- a/osx/boe.items.cpp +++ b/osx/boe.items.cpp @@ -870,8 +870,8 @@ void put_item_graphics(cDialog& me) } for (i = 0; i < 6; i++) { - std::ostringstream sout("pc"); - sout << i + 1; + std::ostringstream sout; + sout << "pc" << i + 1; std::string id = sout.str(); if ((univ.party[i].main_status == 1) && (pc_has_space(i) < 24) && ((!is_combat()) || (current_pc == i))) { @@ -898,8 +898,8 @@ void put_item_graphics(cDialog& me) else me["down"].show(); for (i = 0; i < 8; i++) { - std::ostringstream sout("item"); - sout << i + 1; + std::ostringstream sout; + sout << "item" << i + 1; std::string pict = sout.str() + "-g", name = sout.str() + "-name"; std::string detail = sout.str() + "-detail", weight = sout.str() + "-weight"; @@ -940,8 +940,8 @@ void put_item_graphics(cDialog& me) for (i = 0; i < 6; i++) if (univ.party[i].main_status == 1) { - std::ostringstream sout("pc"); - sout << i + 1 << "-g"; + std::ostringstream sout; + sout << "pc" << i + 1 << "-g"; dynamic_cast(me[sout.str()]).setPict(univ.party[i].which_graphic); } } @@ -966,14 +966,12 @@ bool display_item_event_filter(cDialog& me, std::string id, eKeyMod mods) put_item_graphics(me); } } else if(id.substr(0,2) == "pc") { - sscanf("pc%d", id.c_str(), ¤t_getting_pc); - current_getting_pc--; + current_getting_pc = id[2] - '1'; put_item_graphics(me); } else { if(current_getting_pc == 6) return true; short item_hit; - sscanf("item%d", id.c_str(), &item_hit); - item_hit--; + item_hit = id[4] - '1'; item_hit += first_item_shown; if(item_array[item_hit] >= NUM_TOWN_ITEMS) return true; @@ -1055,7 +1053,7 @@ bool display_item(location from_loc,short pc_num,short mode, bool check_containe } if (!pc_gworld_loaded) - pc_gworld.loadFromImage(*ResMgr::get(902)); + pc_gworld.loadFromImage(*ResMgr::get("pcs")); cDialog itemDialog("get-items.xml"); itemDialog.attachClickHandlers(display_item_event_filter, {"done", "up", "down"}); @@ -1070,8 +1068,8 @@ bool display_item(location from_loc,short pc_num,short mode, bool check_containe else title.setText("Getting all nearby items:"); for(i = 1; i <= 8; i++) { - std::ostringstream sout("item"); - sout << i << "-key"; + std::ostringstream sout; + sout << "item" << i << "-key"; itemDialog[sout.str()].attachKey({false, static_cast('`' + i), mod_none}); itemDialog[sout.str()].attachClickHandler(display_item_event_filter); } diff --git a/osx/boe.text.cpp b/osx/boe.text.cpp index fe59129d2..8c20c54f0 100644 --- a/osx/boe.text.cpp +++ b/osx/boe.text.cpp @@ -1063,8 +1063,8 @@ void print_monst_attacks(m_num_t m_type,short target) //// void damaged_message(short damage,short type) { - std::ostringstream sout(" "); - sout << get_str("monster-abilities",130 + type); + std::ostringstream sout; + sout << " " << get_str("monster-abilities",130 + type); sout << " for " << damage; add_string_to_buf(sout.str().c_str()); }