Return of the on-stack buffer.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40767 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
+21
-13
@@ -427,23 +427,31 @@ BString::AdoptChars(BString& string, int32 charCount)
|
|||||||
BString&
|
BString&
|
||||||
BString::SetToFormat(const char* format, ...)
|
BString::SetToFormat(const char* format, ...)
|
||||||
{
|
{
|
||||||
|
int32 bufferSize = 1024;
|
||||||
|
char buffer[bufferSize];
|
||||||
|
|
||||||
va_list arg;
|
va_list arg;
|
||||||
va_start(arg, format);
|
va_start(arg, format);
|
||||||
int32 bytes = vsnprintf(LockBuffer(0), Length() + 1, format, arg);
|
int32 bytes = vsnprintf(buffer, bufferSize, format, arg);
|
||||||
va_end(arg);
|
va_end(arg);
|
||||||
|
|
||||||
if (bytes <= Length()) {
|
if (bytes < 0)
|
||||||
if (bytes < 0)
|
return Truncate(0);
|
||||||
bytes = 0;
|
|
||||||
UnlockBuffer(bytes);
|
if (bytes < bufferSize) {
|
||||||
} else {
|
SetTo(buffer);
|
||||||
va_list arg2;
|
return *this;
|
||||||
va_start(arg2, format);
|
|
||||||
bytes = vsnprintf(LockBuffer(bytes), bytes + 1, format, arg2);
|
|
||||||
va_end(arg2);
|
|
||||||
UnlockBuffer(bytes);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
va_list arg2;
|
||||||
|
va_start(arg2, format);
|
||||||
|
bytes = vsnprintf(LockBuffer(bytes), bytes + 1, format, arg2);
|
||||||
|
va_end(arg2);
|
||||||
|
|
||||||
|
if (bytes < 0)
|
||||||
|
bytes = 0;
|
||||||
|
|
||||||
|
UnlockBuffer(bytes);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user