diff options
author | dolorous <dolorous@c06c8d41-db1a-0410-9941-cceddc491573> | 2008-06-25 19:47:37 +0000 |
---|---|---|
committer | dolorous <dolorous@c06c8d41-db1a-0410-9941-cceddc491573> | 2008-06-25 19:47:37 +0000 |
commit | e3b9a7a1e14dd81cace9e2241679c5a92eba6006 (patch) | |
tree | e3f48acadb2eb14be1cd282b11496622be261e4a /crawl-ref/source/macro.cc | |
parent | eef749ceb30bf5694dfe06646fde3f2493dc1fa0 (diff) | |
download | crawl-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/macro.cc')
-rw-r--r-- | crawl-ref/source/macro.cc | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/crawl-ref/source/macro.cc b/crawl-ref/source/macro.cc index 2f2ad22ff3..5f2542bf39 100644 --- a/crawl-ref/source/macro.cc +++ b/crawl-ref/source/macro.cc @@ -101,16 +101,16 @@ static bool is_userfunction(const keyseq &seq) return (userfunc_index(seq) != -1); } -const char *get_userfunction(int key) +std::string get_userfunction(int key) { int index = userfunc_index(key); - return (index == -1? NULL : userfunctions[index].c_str()); + return (index == -1 ? NULL : userfunctions[index]); } -static const char *get_userfunction(const keyseq &seq) +static std::string get_userfunction(const keyseq &seq) { int index = userfunc_index(seq); - return (index == -1? NULL : userfunctions[index].c_str()); + return (index == -1 ? NULL : userfunctions[index]); } static bool userfunc_referenced(int index, const macromap &mm) |