Make the BString& version of SetTo() behave like BeOS, that length < 0 is means "until the end". This makes CopyInto() acting alike too. Note the char * version crashes in BeOS, instead we act like the other version for consistency.
There are many other calls that crash in BeOS when called with invalid args, should we attempt to sanitize them or call debugger() instead ? git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25372 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
0fbe0299d3
commit
8e3f5e8959
@ -17,6 +17,7 @@
|
||||
#include <String.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
@ -259,6 +260,8 @@ BString::operator=(char c)
|
||||
BString&
|
||||
BString::SetTo(const char* string, int32 maxLength)
|
||||
{
|
||||
if (maxLength < 0)
|
||||
maxLength = INT32_MAX;
|
||||
maxLength = strlen_clamp(safestr(string), maxLength);
|
||||
if (_DetachWith("", maxLength) == B_OK)
|
||||
memcpy(fPrivateData, string, maxLength);
|
||||
@ -309,6 +312,8 @@ BString::Adopt(BString& from)
|
||||
BString&
|
||||
BString::SetTo(const BString& string, int32 maxLength)
|
||||
{
|
||||
if (maxLength < 0)
|
||||
maxLength = INT32_MAX;
|
||||
if (fPrivateData != string.fPrivateData
|
||||
// make sure we reassing in case length is different
|
||||
|| (fPrivateData == string.fPrivateData && Length() > maxLength)) {
|
||||
|
Loading…
Reference in New Issue
Block a user