summaryrefslogtreecommitdiff
path: root/src/VBox/Runtime/common/string/stringalloc.cpp
diff options
context:
space:
mode:
authorvboxsync <vboxsync@cfe28804-0f27-0410-a406-dd0f0b0b656f>2010-06-21 08:35:09 +0000
committervboxsync <vboxsync@cfe28804-0f27-0410-a406-dd0f0b0b656f>2010-06-21 08:35:09 +0000
commit9d9178f186849d69f7c4d09cd876cfc7eac2b570 (patch)
tree17964982fc6a3bb5ace6d26f5ec799c75e96f5cf /src/VBox/Runtime/common/string/stringalloc.cpp
parentb98873484b5c39d4524f5140b0d022d73495e058 (diff)
downloadVirtualBox-svn-9d9178f186849d69f7c4d09cd876cfc7eac2b570.tar.gz
*: Replaced memchr(psz, '\0', cb) with RTStrEnd(psz, cb) and worked around memchr(,, RTSTR_MAX) issue in RTStrEnd. Here (linux.amd64 / glibc-2.10.1-r1) memchr fails for cb > ~(size_t)11. Since RTSTR_MAX is ~(size_t)0, this behavior breaks several IPRT string APIs.
git-svn-id: https://www.virtualbox.org/svn/vbox/trunk@30320 cfe28804-0f27-0410-a406-dd0f0b0b656f
Diffstat (limited to 'src/VBox/Runtime/common/string/stringalloc.cpp')
-rw-r--r--src/VBox/Runtime/common/string/stringalloc.cpp9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/VBox/Runtime/common/string/stringalloc.cpp b/src/VBox/Runtime/common/string/stringalloc.cpp
index e52d40075cf..d7b2f1fc007 100644
--- a/src/VBox/Runtime/common/string/stringalloc.cpp
+++ b/src/VBox/Runtime/common/string/stringalloc.cpp
@@ -131,9 +131,9 @@ RT_EXPORT_SYMBOL(RTStrDupEx);
RTDECL(char *) RTStrDupN(const char *pszString, size_t cchMax)
{
AssertPtr(pszString);
- char *pszEnd = (char *)memchr(pszString, '\0', cchMax);
- size_t cch = pszEnd ? (uintptr_t)pszEnd - (uintptr_t)pszString : cchMax;
- char *pszDst = (char *)RTMemAlloc(cch + 1);
+ char const *pszEnd = RTStrEnd(pszString, cchMax);
+ size_t cch = pszEnd ? (uintptr_t)pszEnd - (uintptr_t)pszString : cchMax;
+ char *pszDst = (char *)RTMemAlloc(cch + 1);
if (pszDst)
{
memcpy(pszDst, pszString, cch);
@@ -261,7 +261,8 @@ RTDECL(int) RTStrATruncate(char **ppsz, size_t cchNew)
else
{
AssertPtrReturn(pszOld, VERR_OUT_OF_RANGE);
- char *pszZero = (char *)memchr(pszOld, '\0', cchNew + 63);
+ AssertPtrReturn(cchNew < ~(size_t)64, VERR_OUT_OF_RANGE);
+ char *pszZero = RTStrEnd(pszOld, cchNew + 63);
AssertReturn(!pszZero || (size_t)(pszZero - pszOld) >= cchNew, VERR_OUT_OF_RANGE);
pszOld[cchNew] = '\0';
if (!pszZero)