From a4a418a679f1ac760a8763edd856f0178cfc6dde Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Fri, 25 May 2012 07:18:52 +0000 Subject: Merged the composable_generator branch into the trunk git-svn-id: http://mc-server.googlecode.com/svn/trunk@504 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/StringUtils.cpp | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) (limited to 'source/StringUtils.cpp') diff --git a/source/StringUtils.cpp b/source/StringUtils.cpp index 46c20b3d8..97571f521 100644 --- a/source/StringUtils.cpp +++ b/source/StringUtils.cpp @@ -38,23 +38,15 @@ AString & AppendVPrintf(AString & str, const char *format, va_list args) #endif // _MSC_VER // Allocate a buffer and printf into it: - std::auto_ptr tmp(new char[len + 1]); - ASSERT(tmp.get() != NULL); // Why not alloced? Is the length reasonable? - if (tmp.get() == NULL) - { - throw std::bad_alloc(); - } + str.resize(len + 1); + // HACK: we're accessing AString's internal buffer in a way that is NOT guaranteed to always work. But it works on all STL implementations tested. + // I can't think of any other way that is safe, doesn't allocate twice as much space as needed and doesn't use C++11 features like the move constructor #ifdef _MSC_VER - if ((len = vsprintf_s(tmp.get(), len + 1, format, args)) != -1) - { - str.append(tmp.get(), len); - } - ASSERT(len != -1); + vsprintf_s((char *)str.data(), len + 1, format, args); #else // _MSC_VER - vsnprintf(tmp.get(), len + 1, format, args); - str.append(tmp.get(), len); + vsnprintf((char *)str.data(), len + 1, format, args); #endif // else _MSC_VER - + str.resize(len); return str; } -- cgit v1.2.3