From 3838fb9359a8b9895ba8b554ecdfb92f5ff02278 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Sundstr=C3=B6m?= Date: Sun, 27 Feb 2011 15:19:54 +0000 Subject: [PATCH] Using the buffer of the string instead of one on the stack. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40726 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kits/support/String.cpp | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/kits/support/String.cpp b/src/kits/support/String.cpp index b7c74aa575..51918f4b3e 100644 --- a/src/kits/support/String.cpp +++ b/src/kits/support/String.cpp @@ -427,20 +427,14 @@ BString::AdoptChars(BString& string, int32 charCount) BString& BString::SetToArguments(const char* format, ...) { - int32 bufferSize = 128; - char buffer[bufferSize]; - va_list arg; va_start(arg, format); - int32 bytes = vsnprintf(buffer, bufferSize, format, arg); + int32 bytes = vsnprintf(LockBuffer(0), Length() + 1, format, arg); va_end(arg); - - if (bytes < 0) { - return *this; - } - if (bytes < bufferSize) { - SetTo(buffer); + if (bytes <= Length()) { + bytes = bytes < 0 ? 0 : bytes; + UnlockBuffer(bytes); } else { va_list arg2; va_start(arg2, format);