diff options
author | madmaxoft <github@xoft.cz> | 2014-01-08 14:23:15 +0100 |
---|---|---|
committer | madmaxoft <github@xoft.cz> | 2014-01-08 14:23:15 +0100 |
commit | 38d0bdf00a370fa12ce4611789439fe8a57880e8 (patch) | |
tree | 9029ee06dad33f7ebd9329a26f352cc60358d410 /src | |
parent | Merge pull request #519 from mc-server/sigterm (diff) | |
download | cuberite-38d0bdf00a370fa12ce4611789439fe8a57880e8.tar cuberite-38d0bdf00a370fa12ce4611789439fe8a57880e8.tar.gz cuberite-38d0bdf00a370fa12ce4611789439fe8a57880e8.tar.bz2 cuberite-38d0bdf00a370fa12ce4611789439fe8a57880e8.tar.lz cuberite-38d0bdf00a370fa12ce4611789439fe8a57880e8.tar.xz cuberite-38d0bdf00a370fa12ce4611789439fe8a57880e8.tar.zst cuberite-38d0bdf00a370fa12ce4611789439fe8a57880e8.zip |
Diffstat (limited to '')
-rw-r--r-- | src/StringUtils.cpp | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/src/StringUtils.cpp b/src/StringUtils.cpp index 5d16616c5..0b38297ef 100644 --- a/src/StringUtils.cpp +++ b/src/StringUtils.cpp @@ -47,15 +47,13 @@ AString & AppendVPrintf(AString & str, const char *format, va_list args) #endif // _MSC_VER // Allocate a buffer and printf into it: - 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 + std::vector<char> Buffer(len + 1); #ifdef _MSC_VER - vsprintf_s((char *)str.data(), len + 1, format, args); + vsprintf_s((char *)&(Buffer.front()), Buffer.size(), format, args); #else // _MSC_VER - vsnprintf((char *)str.data(), len + 1, format, args); + vsnprintf((char *)&(Buffer.front()), Buffer.size(), format, args); #endif // else _MSC_VER - str.resize(len); + str.append(&(Buffer.front()), Buffer.size() - 1); return str; } |