- Timestamp:
- May 19, 2015 11:00:07 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/glue/string.cpp
r52554 r55942 51 51 size_t cwc; 52 52 int vrc = ::RTStrCalcUtf16LenEx(a_pszSrc, a_cchMax, &cwc); 53 if (RT_FAILURE(vrc)) 54 { 55 /* ASSUME: input is valid Utf-8. Fake out of memory error. */ 53 if (RT_SUCCESS(vrc)) 54 { 55 m_bstr = ::SysAllocStringByteLen(NULL, (unsigned)(cwc * sizeof(OLECHAR))); 56 if (RT_LIKELY(m_bstr)) 57 { 58 PRTUTF16 pwsz = (PRTUTF16)m_bstr; 59 vrc = ::RTStrToUtf16Ex(a_pszSrc, a_cchMax, &pwsz, cwc + 1, NULL); 60 if (RT_SUCCESS(vrc)) 61 return; 62 63 /* This should not happen! */ 64 AssertRC(vrc); 65 cleanup(); 66 } 67 } 68 else /* ASSUME: input is valid Utf-8. Fake out of memory error. */ 56 69 AssertLogRelMsgFailed(("%Rrc %.*Rhxs\n", vrc, RTStrNLen(a_pszSrc, a_cchMax), a_pszSrc)); 57 throw std::bad_alloc(); 58 } 59 60 m_bstr = ::SysAllocStringByteLen(NULL, (unsigned)(cwc * sizeof(OLECHAR))); 61 if (RT_UNLIKELY(!m_bstr)) 62 throw std::bad_alloc(); 63 64 PRTUTF16 pwsz = (PRTUTF16)m_bstr; 65 vrc = ::RTStrToUtf16Ex(a_pszSrc, a_cchMax, &pwsz, cwc + 1, NULL); 66 if (RT_FAILURE(vrc)) 67 { 68 /* This should not happen! */ 69 AssertRC(vrc); 70 cleanup(); 71 throw std::bad_alloc(); 72 } 70 throw std::bad_alloc(); 73 71 } 74 72 … … 81 79 { 82 80 size_t cb = length() + 1; 83 *pstr = (char*)nsMemory::Alloc(cb); 84 if (RT_UNLIKELY(!*pstr)) 81 *pstr = (char *)nsMemory::Alloc(cb); 82 if (RT_LIKELY(*pstr)) 83 memcpy(*pstr, c_str(), cb); 84 else 85 85 throw std::bad_alloc(); 86 memcpy(*pstr, c_str(), cb);87 86 } 88 87 … … 90 89 { 91 90 size_t cb = length() + 1; 92 *pstr = (char*)nsMemory::Alloc(cb); 93 if (RT_UNLIKELY(!*pstr)) 94 return E_OUTOFMEMORY; 95 memcpy(*pstr, c_str(), cb); 96 return S_OK; 91 *pstr = (char *)nsMemory::Alloc(cb); 92 if (RT_LIKELY(*pstr)) 93 { 94 memcpy(*pstr, c_str(), cb); 95 return S_OK; 96 } 97 return E_OUTOFMEMORY; 97 98 } 98 99 #endif
Note:
See TracChangeset
for help on using the changeset viewer.