From 8e3f5e895985f70c5922879c0ee24f5bde64a698 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= Date: Thu, 8 May 2008 12:56:55 +0000 Subject: [PATCH] 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 --- src/kits/support/String.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/kits/support/String.cpp b/src/kits/support/String.cpp index f941f876a3..df5374bea6 100644 --- a/src/kits/support/String.cpp +++ b/src/kits/support/String.cpp @@ -17,6 +17,7 @@ #include #include +#include #include #include @@ -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)) {