From 9d9178f186849d69f7c4d09cd876cfc7eac2b570 Mon Sep 17 00:00:00 2001 From: vboxsync Date: Mon, 21 Jun 2010 08:35:09 +0000 Subject: *: 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 --- src/VBox/Runtime/common/string/stringalloc.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/VBox/Runtime/common/string/stringalloc.cpp') 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) -- cgit v1.2.1