summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/stuff.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/stuff.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/stuff.cc')
-rw-r--r--crawl-ref/source/stuff.cc6
1 files changed, 3 insertions, 3 deletions
diff --git a/crawl-ref/source/stuff.cc b/crawl-ref/source/stuff.cc
index 92ce879e89..352fda180c 100644
--- a/crawl-ref/source/stuff.cc
+++ b/crawl-ref/source/stuff.cc
@@ -1057,7 +1057,7 @@ static std::string _list_alternative_yes(char yes1, char yes2,
return help;
}
-static const char* _list_allowed_keys(char yes1, char yes2,
+static std::string _list_allowed_keys(char yes1, char yes2,
bool lowered = false,
bool allow_all = false)
{
@@ -1069,7 +1069,7 @@ static const char* _list_allowed_keys(char yes1, char yes2,
result += (lowered ? "/n/q" : "/N/Q");
result += "]";
- return (result.c_str());
+ return (result);
}
// Like yesno(), but returns 0 for no, 1 for yes, and -1 for quit.
@@ -1083,7 +1083,7 @@ int yesnoquit( const char* str, bool safe, int safeanswer, bool allow_all,
std::string prompt = make_stringf("%s%s ", str ? str : "Buggy prompt?",
_list_allowed_keys(alt_yes, alt_yes2,
- safe, allow_all));
+ safe, allow_all).c_str());
while (true)
{
mpr(prompt.c_str(), MSGCH_PROMPT);