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:
parent
ea76002c38
commit
146d274d81
@ -427,23 +427,31 @@ BString::AdoptChars(BString& string, int32 charCount)
|
||||
BString&
|
||||
BString::SetToFormat(const char* format, ...)
|
||||
{
|
||||
int32 bufferSize = 1024;
|
||||
char buffer[bufferSize];
|
||||
|
||||
va_list arg;
|
||||
va_start(arg, format);
|
||||
int32 bytes = vsnprintf(LockBuffer(0), Length() + 1, format, arg);
|
||||
int32 bytes = vsnprintf(buffer, bufferSize, format, arg);
|
||||
va_end(arg);
|
||||
|
||||
if (bytes <= Length()) {
|
||||
if (bytes < 0)
|
||||
bytes = 0;
|
||||
UnlockBuffer(bytes);
|
||||
} else {
|
||||
va_list arg2;
|
||||
va_start(arg2, format);
|
||||
bytes = vsnprintf(LockBuffer(bytes), bytes + 1, format, arg2);
|
||||
va_end(arg2);
|
||||
UnlockBuffer(bytes);
|
||||
|
||||
if (bytes < 0)
|
||||
return Truncate(0);
|
||||
|
||||
if (bytes < bufferSize) {
|
||||
SetTo(buffer);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user