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/delay.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/delay.cc')
-rw-r--r-- | crawl-ref/source/delay.cc | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/crawl-ref/source/delay.cc b/crawl-ref/source/delay.cc index d215c38e39..eb9393d4f4 100644 --- a/crawl-ref/source/delay.cc +++ b/crawl-ref/source/delay.cc @@ -211,13 +211,13 @@ static int _recite_to_monsters(int x, int y, int pow, int unused) return (1); } -static const char* _get_recite_speech(const std::string key, int weight) +static std::string _get_recite_speech(const std::string key, int weight) { seed_rng( weight + you.x_pos + you.y_pos); const std::string str = getSpeakString("zin_recite_speech_" + key); if (!str.empty()) - return (str.c_str()); + return (str); // in case nothing is found if (key == "start") @@ -429,7 +429,7 @@ void stop_delay( bool stop_stair_travel ) case DELAY_RECITE: mprf(MSGCH_PLAIN, "You stop %s.", - _get_recite_speech("other", you.num_turns + delay.duration)); + _get_recite_speech("other", you.num_turns + delay.duration).c_str()); _pop_delay(); break; @@ -683,7 +683,7 @@ void handle_delay( void ) break; case DELAY_RECITE: mprf(MSGCH_PLAIN, "You %s", - _get_recite_speech("start", you.num_turns + delay.duration)); + _get_recite_speech("start", you.num_turns + delay.duration).c_str()); if (apply_area_visible(_recite_to_monsters, delay.parm1)) viewwindow(true, false); @@ -890,7 +890,7 @@ void handle_delay( void ) break; case DELAY_RECITE: mprf(MSGCH_MULTITURN_ACTION, "You continue %s.", - _get_recite_speech("other", you.num_turns + delay.duration+1)); + _get_recite_speech("other", you.num_turns + delay.duration+1).c_str()); if (apply_area_visible(_recite_to_monsters, delay.parm1)) viewwindow(true, false); @@ -1034,7 +1034,7 @@ static void _finish_delay(const delay_queue_item &delay) case DELAY_RECITE: mprf(MSGCH_PLAIN, "You finish %s.", - _get_recite_speech("other", you.num_turns + delay.duration)); + _get_recite_speech("other", you.num_turns + delay.duration).c_str()); break; case DELAY_PASSWALL: |