[haiku-commits] r40726 - haiku/trunk/src/kits/support

  • From: jonas@xxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Sun, 27 Feb 2011 16:19:54 +0100 (CET)

Author: kirilla
Date: 2011-02-27 16:19:54 +0100 (Sun, 27 Feb 2011)
New Revision: 40726
Changeset: http://dev.haiku-os.org/changeset/40726

Modified:
   haiku/trunk/src/kits/support/String.cpp
Log:
Using the buffer of the string instead of one on the stack.

Modified: haiku/trunk/src/kits/support/String.cpp
===================================================================
--- haiku/trunk/src/kits/support/String.cpp     2011-02-27 13:36:13 UTC (rev 
40725)
+++ haiku/trunk/src/kits/support/String.cpp     2011-02-27 15:19:54 UTC (rev 
40726)
@@ -427,20 +427,14 @@
 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);


Other related posts: