diff options
author | Robert Vollmert <rvollmert@gmx.net> | 2009-12-17 15:51:51 +0100 |
---|---|---|
committer | Robert Vollmert <rvollmert@gmx.net> | 2009-12-17 15:51:51 +0100 |
commit | 354816b2ff6361a8286a547c0c130e0de170f0a7 (patch) | |
tree | 8bc4e53c456ec49fce0c64a4ba3828b61c48482a /crawl-ref/source/libutil.cc | |
parent | 1ab177757bec9eb28482785f75fd8a4fb8a1313c (diff) | |
download | crawl-ref-354816b2ff6361a8286a547c0c130e0de170f0a7.tar.gz crawl-ref-354816b2ff6361a8286a547c0c130e0de170f0a7.zip |
Fix bad varargs handling.
You can't pass a va_list to a variadic function.
Diffstat (limited to 'crawl-ref/source/libutil.cc')
-rw-r--r-- | crawl-ref/source/libutil.cc | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/crawl-ref/source/libutil.cc b/crawl-ref/source/libutil.cc index 0243452e77..ce7fcbb429 100644 --- a/crawl-ref/source/libutil.cc +++ b/crawl-ref/source/libutil.cc @@ -136,24 +136,30 @@ std::string strip_filename_unsafe_chars(const std::string &s) return replace_all_of(s, " .&`\"\'|;{}()[]<>*%$#@!~?", ""); } -std::string make_stringf(const char *s, ...) +std::string vmake_stringf(const char* s, va_list args) { - va_list args; - va_start(args, s); char buf1[400]; size_t len = vsnprintf(buf1, sizeof buf1, s, args); - va_end(args); if (len < sizeof buf1) return (buf1); + char *buf2 = (char*)malloc(len + 1); - va_start(args, s); vsnprintf(buf2, len + 1, s, args); std::string ret(buf2); free(buf2); - va_end(args); + return (ret); } +std::string make_stringf(const char *s, ...) +{ + va_list args; + va_start(args, s); + std::string ret = vmake_stringf(s, args); + va_end(args); + return ret; +} + std::string &escape_path_spaces(std::string &s) { std::string result; |