diff options
author | Vsevolod Kozlov <zaba@thorium.homeunix.org> | 2009-12-30 15:41:22 +0300 |
---|---|---|
committer | Vsevolod Kozlov <zaba@thorium.homeunix.org> | 2009-12-30 15:44:32 +0300 |
commit | 964f798ab9503b70e423411b6576274f02ecf74a (patch) | |
tree | 11e65a4b1b58cce33dca90b5ed3b5fe31b16bf5c | |
parent | dc6da664d1b8aebf9c7baf96dc26513863affadb (diff) | |
download | crawl-ref-964f798ab9503b70e423411b6576274f02ecf74a.tar.gz crawl-ref-964f798ab9503b70e423411b6576274f02ecf74a.zip |
vmake_stringf: Copy the va_list argument for the second vsnprintf call.
It needs to be copied, otherwise the second call to vsnprintf will be passed
a va_list that has been messed up by the first call, and weird segfaults will
occur. (They did for me.)
-rw-r--r-- | crawl-ref/source/libutil.cc | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/crawl-ref/source/libutil.cc b/crawl-ref/source/libutil.cc index 26243f405c..bd3440d0fb 100644 --- a/crawl-ref/source/libutil.cc +++ b/crawl-ref/source/libutil.cc @@ -143,12 +143,15 @@ std::string strip_filename_unsafe_chars(const std::string &s) std::string vmake_stringf(const char* s, va_list args) { char buf1[400]; + va_list orig_args; + va_copy(orig_args, args); size_t len = vsnprintf(buf1, sizeof buf1, s, args); if (len < sizeof buf1) return (buf1); char *buf2 = (char*)malloc(len + 1); - vsnprintf(buf2, len + 1, s, args); + vsnprintf(buf2, len + 1, s, orig_args); + va_end(orig_args); std::string ret(buf2); free(buf2); |