summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/output.cc
diff options
context:
space:
mode:
authordolorous <dolorous@c06c8d41-db1a-0410-9941-cceddc491573>2008-06-25 19:47:37 +0000
committerdolorous <dolorous@c06c8d41-db1a-0410-9941-cceddc491573>2008-06-25 19:47:37 +0000
commite3b9a7a1e14dd81cace9e2241679c5a92eba6006 (patch)
treee3f48acadb2eb14be1cd282b11496622be261e4a /crawl-ref/source/output.cc
parenteef749ceb30bf5694dfe06646fde3f2493dc1fa0 (diff)
downloadcrawl-ref-e3b9a7a1e14dd81cace9e2241679c5a92eba6006.tar.gz
crawl-ref-e3b9a7a1e14dd81cace9e2241679c5a92eba6006.zip
For functions that return char*'s, don't return a c_str() of an
std::string, since as soon as the function returns, the std::string goes out of scope, and the c_str() becomes a dangling pointer, which usually points to the same area as before, but occasionally points to garbage. Instead, make them return std::string's, and call c_str() on the return value outside the functions. Among other things, this should fix [1999515]. Note that I've only fixed direct c_str() returns for now. There might be some indirect ones that I missed. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@6139 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/output.cc')
-rw-r--r--crawl-ref/source/output.cc17
1 files changed, 9 insertions, 8 deletions
diff --git a/crawl-ref/source/output.cc b/crawl-ref/source/output.cc
index 6074856306..7da5db1f69 100644
--- a/crawl-ref/source/output.cc
+++ b/crawl-ref/source/output.cc
@@ -1005,7 +1005,7 @@ static bool _mons_hostile(const monsters *mon)
return (!mons_friendly(mon) && !mons_neutral(mon));
}
-static const char* _get_monster_name(const monsters *mon, bool list_a = false)
+static std::string _get_monster_name(const monsters *mon, bool list_a = false)
{
std::string desc = "";
@@ -1043,7 +1043,8 @@ static const char* _get_monster_name(const monsters *mon, bool list_a = false)
desc += ")";
}
}
- return desc.c_str();
+
+ return (desc);
}
// Returns true if the first monster is more aggressive (in terms of
@@ -1113,11 +1114,11 @@ static void _get_visible_monsters(std::vector<std::string>& describe)
if (i > 0 && _compare_monsters_attitude(mons[i-1], mons[i]))
{
if (count == 1)
- describe.push_back(_get_monster_name(mons[i-1], true));
+ describe.push_back(_get_monster_name(mons[i-1], true).c_str());
else
{
describe.push_back(number_in_words(count) + " "
- + pluralise(_get_monster_name(mons[i-1])));
+ + pluralise(_get_monster_name(mons[i-1]).c_str()));
}
count = 0;
}
@@ -1127,12 +1128,12 @@ static void _get_visible_monsters(std::vector<std::string>& describe)
if (mons.size() == 1
|| _compare_monsters_attitude(mons[size-2], mons[size-1]))
{
- describe.push_back(_get_monster_name(mons[size-1], true));
+ describe.push_back(_get_monster_name(mons[size-1], true).c_str());
}
else
{
describe.push_back(number_in_words(count) + " "
- + pluralise(_get_monster_name(mons[size-1])));
+ + pluralise(_get_monster_name(mons[size-1]).c_str()));
}
}
@@ -1621,7 +1622,7 @@ static void _print_overview_screen_equip(column_composer& cols,
{
const int item_idx = you.equip[e_order[i]];
const item_def& item = you.inv[item_idx];
- const char* colname = colour_to_str(item.colour);
+ const char* colname = colour_to_str(item.colour).c_str();
const char equip_char = index_to_letter(item_idx);
char buf2[50];
@@ -1802,7 +1803,7 @@ static std::vector<formatted_string> _get_overview_stats()
else
{
snprintf(god_colour_tag, sizeof god_colour_tag, "<%s>",
- colour_to_str(god_colour(you.religion)));
+ colour_to_str(god_colour(you.religion)).c_str());
// piety rankings
int prank = piety_rank() - 1;
if (prank < 0 || you.religion == GOD_XOM)