summaryrefslogtreecommitdiffstats
path: root/source/StringUtils.cpp
diff options
context:
space:
mode:
authormadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-05-25 09:18:52 +0200
committermadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-05-25 09:18:52 +0200
commita4a418a679f1ac760a8763edd856f0178cfc6dde (patch)
tree85300ca3a2b3a942998a0c864ae90894857ebf5f /source/StringUtils.cpp
parentFixed output directory structure in the "Release profiled" configuration (diff)
downloadcuberite-a4a418a679f1ac760a8763edd856f0178cfc6dde.tar
cuberite-a4a418a679f1ac760a8763edd856f0178cfc6dde.tar.gz
cuberite-a4a418a679f1ac760a8763edd856f0178cfc6dde.tar.bz2
cuberite-a4a418a679f1ac760a8763edd856f0178cfc6dde.tar.lz
cuberite-a4a418a679f1ac760a8763edd856f0178cfc6dde.tar.xz
cuberite-a4a418a679f1ac760a8763edd856f0178cfc6dde.tar.zst
cuberite-a4a418a679f1ac760a8763edd856f0178cfc6dde.zip
Diffstat (limited to '')
-rw-r--r--source/StringUtils.cpp20
1 files changed, 6 insertions, 14 deletions
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<char> 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;
}