diff options
author | Michael Stahl <mstahl@redhat.com> | 2015-02-05 22:07:28 +0100 |
---|---|---|
committer | Michael Stahl <mstahl@redhat.com> | 2015-02-05 23:33:07 +0100 |
commit | b0ef5cf258f3a84054c052f0a09a208dbc17fdf3 (patch) | |
tree | 3e5d524d9acf1fce1a67862497ccbeb5492e9703 /sal | |
parent | 30f6ec7cfdf63cea265148bbe3a07d8df34e96d5 (diff) |
sal: add some argument checking assertions for strings and buffers
Also remove some now redundant asserts from headers.
Some of these actually trigger on unit tests so are commented out.
Change-Id: I07c6b2b2bd175361691a141f22eec584e3ab8f0b
Diffstat (limited to 'sal')
-rw-r--r-- | sal/rtl/strbuf.cxx | 16 | ||||
-rw-r--r-- | sal/rtl/string.cxx | 12 | ||||
-rw-r--r-- | sal/rtl/strtmpl.cxx | 73 | ||||
-rw-r--r-- | sal/rtl/ustrbuf.cxx | 23 | ||||
-rw-r--r-- | sal/rtl/ustring.cxx | 39 |
5 files changed, 155 insertions, 8 deletions
diff --git a/sal/rtl/strbuf.cxx b/sal/rtl/strbuf.cxx index f75d0cc7ef57..bb42dee4a0d4 100644 --- a/sal/rtl/strbuf.cxx +++ b/sal/rtl/strbuf.cxx @@ -29,6 +29,8 @@ void SAL_CALL rtl_stringbuffer_newFromStr_WithLength( rtl_String ** newStr, const sal_Char * value, sal_Int32 count ) { + assert(newStr); + assert(count >= 0); if (!value) { rtl_string_new_WithLength( newStr, 16 ); @@ -48,6 +50,9 @@ sal_Int32 SAL_CALL rtl_stringbuffer_newFromStringBuffer( rtl_String ** newStr, sal_Int32 capacity, rtl_String * oldStr ) { + assert(newStr); + assert(oldStr); + assert(capacity >= 0); sal_Int32 newCapacity = capacity; if (newCapacity < oldStr->length) @@ -67,6 +72,9 @@ sal_Int32 SAL_CALL rtl_stringbuffer_newFromStringBuffer( rtl_String ** newStr, void SAL_CALL rtl_stringbuffer_ensureCapacity (rtl_String ** This, sal_Int32* capacity, sal_Int32 minimumCapacity) { + assert(This); +// assert(capacity && *capacity >= 0); +// assert(minimumCapacity >= 0); if (minimumCapacity > *capacity) { rtl_String * pTmp = *This; @@ -94,6 +102,11 @@ void SAL_CALL rtl_stringbuffer_insert( rtl_String ** This, const sal_Char * str, sal_Int32 len ) { + assert(This); + assert(capacity && *capacity >= 0); + assert(offset >= 0 && offset <= (**This).length); + assert(len == 0 || str != nullptr); + assert(len >= 0); sal_Int32 nOldLen; sal_Char * pBuf; sal_Int32 n; @@ -134,6 +147,9 @@ void SAL_CALL rtl_stringbuffer_remove( rtl_String ** This, sal_Int32 start, sal_Int32 len ) { + assert(This); + assert(start >= 0 && start <= (**This).length); + assert(len >= 0); sal_Int32 nTailLen; sal_Char * pBuf; diff --git a/sal/rtl/string.cxx b/sal/rtl/string.cxx index a71ba162d64e..89459dbc2c0c 100644 --- a/sal/rtl/string.cxx +++ b/sal/rtl/string.cxx @@ -88,6 +88,7 @@ static rtl_String const aImplEmpty_rtl_String = sal_Int32 SAL_CALL rtl_str_valueOfFloat(sal_Char * pStr, float f) SAL_THROW_EXTERN_C() { + assert(pStr); rtl_String * pResult = NULL; sal_Int32 nLen; rtl_math_doubleToString( @@ -104,6 +105,7 @@ sal_Int32 SAL_CALL rtl_str_valueOfFloat(sal_Char * pStr, float f) sal_Int32 SAL_CALL rtl_str_valueOfDouble(sal_Char * pStr, double d) SAL_THROW_EXTERN_C() { + assert(pStr); rtl_String * pResult = NULL; sal_Int32 nLen; rtl_math_doubleToString( @@ -119,12 +121,14 @@ sal_Int32 SAL_CALL rtl_str_valueOfDouble(sal_Char * pStr, double d) float SAL_CALL rtl_str_toFloat(sal_Char const * pStr) SAL_THROW_EXTERN_C() { + assert(pStr); return (float) rtl_math_stringToDouble(pStr, pStr + rtl_str_getLength(pStr), '.', 0, 0, 0); } double SAL_CALL rtl_str_toDouble(sal_Char const * pStr) SAL_THROW_EXTERN_C() { + assert(pStr); return rtl_math_stringToDouble(pStr, pStr + rtl_str_getLength(pStr), '.', 0, 0, 0); } @@ -192,10 +196,10 @@ bool SAL_CALL rtl_impl_convertUStringToString(rtl_String ** pTarget, sal_uInt32 nFlags, bool bCheckErrors) { - OSL_ASSERT(pTarget != NULL - && (pSource != NULL || nLength == 0) - && nLength >= 0 - && (nLength == 0 || rtl_isOctetTextEncoding(nEncoding))); + assert(pTarget != nullptr); + assert(pSource != nullptr || nLength == 0); + assert(nLength >= 0); + OSL_ASSERT(nLength == 0 || rtl_isOctetTextEncoding(nEncoding)); if ( !nLength ) rtl_string_new( pTarget ); diff --git a/sal/rtl/strtmpl.cxx b/sal/rtl/strtmpl.cxx index a50c3641949d..bfd61dec767f 100644 --- a/sal/rtl/strtmpl.cxx +++ b/sal/rtl/strtmpl.cxx @@ -61,6 +61,7 @@ static inline void rtl_str_ImplCopy( IMPL_RTL_STRCODE* _pDest, sal_Int32 SAL_CALL IMPL_RTL_STRNAME( getLength )( const IMPL_RTL_STRCODE* pStr ) SAL_THROW_EXTERN_C() { + assert(pStr); #if !IMPL_RTL_IS_USTRING // take advantage of builtin optimisations return strlen( pStr); @@ -86,6 +87,8 @@ sal_Int32 SAL_CALL IMPL_RTL_STRNAME( compare )( const IMPL_RTL_STRCODE* pStr1, const IMPL_RTL_STRCODE* pStr2 ) SAL_THROW_EXTERN_C() { + assert(pStr1); + assert(pStr2); #if !IMPL_RTL_IS_USTRING // take advantage of builtin optimisations return strcmp( pStr1, pStr2); @@ -119,6 +122,8 @@ sal_Int32 SAL_CALL IMPL_RTL_STRNAME( compare_WithLength )( const IMPL_RTL_STRCOD sal_Int32 nStr2Len ) SAL_THROW_EXTERN_C() { + assert(nStr1Len >= 0); + assert(nStr2Len >= 0); #if !IMPL_RTL_IS_USTRING // take advantage of builtin optimisations sal_Int32 nMin = std::min(nStr1Len, nStr2Len); @@ -159,6 +164,9 @@ sal_Int32 SAL_CALL IMPL_RTL_STRNAME( shortenedCompare_WithLength )( const IMPL_R sal_Int32 nShortenedLength ) SAL_THROW_EXTERN_C() { + assert(nStr1Len >= 0); + assert(nStr2Len >= 0); + assert(nShortenedLength >= 0); #if !IMPL_RTL_IS_USTRING // take advantage of builtin optimisations sal_Int32 nMin = std::min(std::min(nStr1Len, nStr2Len), nShortenedLength); @@ -209,6 +217,8 @@ sal_Int32 SAL_CALL IMPL_RTL_STRNAME( reverseCompare_WithLength )( const IMPL_RTL sal_Int32 nStr2Len ) SAL_THROW_EXTERN_C() { + assert(nStr1Len >= 0); + assert(nStr2Len >= 0); const IMPL_RTL_STRCODE* pStr1Run = pStr1+nStr1Len; const IMPL_RTL_STRCODE* pStr2Run = pStr2+nStr2Len; sal_Int32 nRet; @@ -231,6 +241,8 @@ sal_Int32 SAL_CALL IMPL_RTL_STRNAME( compareIgnoreAsciiCase )( const IMPL_RTL_ST const IMPL_RTL_STRCODE* pStr2 ) SAL_THROW_EXTERN_C() { + assert(pStr1); + assert(pStr2); sal_uInt32 c1; do { @@ -256,6 +268,8 @@ sal_Int32 SAL_CALL IMPL_RTL_STRNAME( compareIgnoreAsciiCase_WithLength )( const sal_Int32 nStr2Len ) SAL_THROW_EXTERN_C() { + assert(nStr1Len >= 0); + assert(nStr2Len >= 0); const IMPL_RTL_STRCODE* pStr1End = pStr1 + nStr1Len; const IMPL_RTL_STRCODE* pStr2End = pStr2 + nStr2Len; while ( (pStr1 < pStr1End) && (pStr2 < pStr2End) ) @@ -281,6 +295,9 @@ sal_Int32 SAL_CALL IMPL_RTL_STRNAME( shortenedCompareIgnoreAsciiCase_WithLength sal_Int32 nShortenedLength ) SAL_THROW_EXTERN_C() { + assert(nStr1Len >= 0); + assert(nStr2Len >= 0); + assert(nShortenedLength >= 0); const IMPL_RTL_STRCODE* pStr1End = pStr1 + nStr1Len; const IMPL_RTL_STRCODE* pStr2End = pStr2 + nStr2Len; while ( (nShortenedLength > 0) && @@ -315,6 +332,7 @@ sal_Int32 SAL_CALL IMPL_RTL_STRNAME( hashCode_WithLength )( const IMPL_RTL_STRCO sal_Int32 nLen ) SAL_THROW_EXTERN_C() { + assert(nLen >= 0); sal_uInt32 h = static_cast<sal_uInt32>(nLen); while ( nLen > 0 ) { @@ -331,6 +349,7 @@ sal_Int32 SAL_CALL IMPL_RTL_STRNAME( indexOfChar )( const IMPL_RTL_STRCODE* pStr IMPL_RTL_STRCODE c ) SAL_THROW_EXTERN_C() { + assert(pStr); #if !IMPL_RTL_IS_USTRING // take advantage of builtin optimisations const IMPL_RTL_STRCODE* p = strchr(pStr, c); @@ -365,6 +384,7 @@ sal_Int32 SAL_CALL IMPL_RTL_STRNAME( indexOfChar_WithLength )( const IMPL_RTL_ST IMPL_RTL_STRCODE c ) SAL_THROW_EXTERN_C() { +// assert(nLen >= 0); #if !IMPL_RTL_IS_USTRING // take advantage of builtin optimisations IMPL_RTL_STRCODE* p = (IMPL_RTL_STRCODE*) memchr(pStr, c, nLen); @@ -390,6 +410,7 @@ sal_Int32 SAL_CALL IMPL_RTL_STRNAME( lastIndexOfChar )( const IMPL_RTL_STRCODE* IMPL_RTL_STRCODE c ) SAL_THROW_EXTERN_C() { + assert(pStr); #if !IMPL_RTL_IS_USTRING // take advantage of builtin optimisations const IMPL_RTL_STRCODE* p = strrchr(pStr, c); @@ -415,6 +436,7 @@ sal_Int32 SAL_CALL IMPL_RTL_STRNAME( lastIndexOfChar_WithLength )( const IMPL_RT IMPL_RTL_STRCODE c ) SAL_THROW_EXTERN_C() { + assert(nLen >= 0); pStr += nLen; while ( nLen > 0 ) { @@ -434,6 +456,8 @@ sal_Int32 SAL_CALL IMPL_RTL_STRNAME( indexOfStr )( const IMPL_RTL_STRCODE* pStr, const IMPL_RTL_STRCODE* pSubStr ) SAL_THROW_EXTERN_C() { + assert(pStr); + assert(pSubStr); #if !IMPL_RTL_IS_USTRING // take advantage of builtin optimisations const IMPL_RTL_STRCODE* p = strstr(pStr, pSubStr); @@ -461,6 +485,8 @@ sal_Int32 SAL_CALL IMPL_RTL_STRNAME( indexOfStr_WithLength )( const IMPL_RTL_STR sal_Int32 nSubLen ) SAL_THROW_EXTERN_C() { + assert(nStrLen >= 0); + assert(nSubLen >= 0); /* faster search for a single character */ if ( nSubLen < 2 ) { @@ -535,6 +561,8 @@ sal_Int32 SAL_CALL IMPL_RTL_STRNAME( lastIndexOfStr_WithLength )( const IMPL_RTL sal_Int32 nSubLen ) SAL_THROW_EXTERN_C() { +// assert(nStrLen >= 0); + assert(nSubLen >= 0); /* faster search for a single character */ if ( nSubLen < 2 ) { @@ -591,6 +619,7 @@ void SAL_CALL IMPL_RTL_STRNAME( replaceChar )( IMPL_RTL_STRCODE* pStr, IMPL_RTL_STRCODE cNew ) SAL_THROW_EXTERN_C() { + assert(pStr); while ( *pStr ) { if ( *pStr == cOld ) @@ -608,6 +637,7 @@ void SAL_CALL IMPL_RTL_STRNAME( replaceChar_WithLength )( IMPL_RTL_STRCODE* pStr IMPL_RTL_STRCODE cNew ) SAL_THROW_EXTERN_C() { + assert(nLen >= 0); while ( nLen > 0 ) { if ( *pStr == cOld ) @@ -623,6 +653,7 @@ void SAL_CALL IMPL_RTL_STRNAME( replaceChar_WithLength )( IMPL_RTL_STRCODE* pStr void SAL_CALL IMPL_RTL_STRNAME( toAsciiLowerCase )( IMPL_RTL_STRCODE* pStr ) SAL_THROW_EXTERN_C() { + assert(pStr); while ( *pStr ) { *pStr = rtl::toAsciiLowerCase(IMPL_RTL_USTRCODE(*pStr)); @@ -637,6 +668,7 @@ void SAL_CALL IMPL_RTL_STRNAME( toAsciiLowerCase_WithLength )( IMPL_RTL_STRCODE* sal_Int32 nLen ) SAL_THROW_EXTERN_C() { + assert(nLen >= 0); while ( nLen > 0 ) { *pStr = rtl::toAsciiLowerCase(IMPL_RTL_USTRCODE(*pStr)); @@ -651,6 +683,7 @@ void SAL_CALL IMPL_RTL_STRNAME( toAsciiLowerCase_WithLength )( IMPL_RTL_STRCODE* void SAL_CALL IMPL_RTL_STRNAME( toAsciiUpperCase )( IMPL_RTL_STRCODE* pStr ) SAL_THROW_EXTERN_C() { + assert(pStr); while ( *pStr ) { *pStr = rtl::toAsciiUpperCase(IMPL_RTL_USTRCODE(*pStr)); @@ -665,6 +698,7 @@ void SAL_CALL IMPL_RTL_STRNAME( toAsciiUpperCase_WithLength )( IMPL_RTL_STRCODE* sal_Int32 nLen ) SAL_THROW_EXTERN_C() { + assert(nLen >= 0); while ( nLen > 0 ) { *pStr = rtl::toAsciiUpperCase(IMPL_RTL_USTRCODE(*pStr)); @@ -687,6 +721,7 @@ sal_Int32 SAL_CALL IMPL_RTL_STRNAME( trim )( IMPL_RTL_STRCODE* pStr ) sal_Int32 SAL_CALL IMPL_RTL_STRNAME( trim_WithLength )( IMPL_RTL_STRCODE* pStr, sal_Int32 nLen ) SAL_THROW_EXTERN_C() { + assert(nLen >= 0); sal_Int32 nPreSpaces = 0; sal_Int32 nPostSpaces = 0; sal_Int32 nIndex = nLen-1; @@ -731,6 +766,7 @@ sal_Int32 SAL_CALL IMPL_RTL_STRNAME( trim_WithLength )( IMPL_RTL_STRCODE* pStr, sal_Int32 SAL_CALL IMPL_RTL_STRNAME( valueOfBoolean )( IMPL_RTL_STRCODE* pStr, sal_Bool b ) SAL_THROW_EXTERN_C() { + assert(pStr); if ( b ) { *pStr = 't'; @@ -767,6 +803,7 @@ sal_Int32 SAL_CALL IMPL_RTL_STRNAME( valueOfChar )( IMPL_RTL_STRCODE* pStr, IMPL_RTL_STRCODE c ) SAL_THROW_EXTERN_C() { + assert(pStr); *pStr++ = c; *pStr = 0; return 1; @@ -779,6 +816,7 @@ sal_Int32 SAL_CALL IMPL_RTL_STRNAME( valueOfInt32 )( IMPL_RTL_STRCODE* pStr, sal_Int16 nRadix ) SAL_THROW_EXTERN_C() { + assert(pStr); sal_Char aBuf[RTL_STR_MAX_VALUEOFINT32]; sal_Char* pBuf = aBuf; sal_Int32 nLen = 0; @@ -833,6 +871,7 @@ sal_Int32 SAL_CALL IMPL_RTL_STRNAME( valueOfInt64 )( IMPL_RTL_STRCODE* pStr, sal_Int16 nRadix ) SAL_THROW_EXTERN_C() { + assert(pStr); sal_Char aBuf[RTL_STR_MAX_VALUEOFINT64]; sal_Char* pBuf = aBuf; sal_Int32 nLen = 0; @@ -887,6 +926,7 @@ sal_Int32 SAL_CALL IMPL_RTL_STRNAME( valueOfUInt64 )( IMPL_RTL_STRCODE* pStr, sal_Int16 nRadix ) SAL_THROW_EXTERN_C() { + assert(pStr); sal_Char aBuf[RTL_STR_MAX_VALUEOFUINT64]; sal_Char* pBuf = aBuf; sal_Int32 nLen = 0; @@ -930,6 +970,7 @@ sal_Int32 SAL_CALL IMPL_RTL_STRNAME( valueOfUInt64 )( IMPL_RTL_STRCODE* pStr, sal_Bool SAL_CALL IMPL_RTL_STRNAME( toBoolean )( const IMPL_RTL_STRCODE* pStr ) SAL_THROW_EXTERN_C() { + assert(pStr); if ( *pStr == '1' ) return sal_True; @@ -1029,6 +1070,7 @@ sal_Int32 SAL_CALL IMPL_RTL_STRNAME( toInt32 )( const IMPL_RTL_STRCODE* pStr, sal_Int16 nRadix ) SAL_THROW_EXTERN_C() { + assert(pStr); return IMPL_RTL_STRNAME( toInt )<sal_Int32, sal_uInt32>(pStr, nRadix); } @@ -1036,6 +1078,7 @@ sal_Int64 SAL_CALL IMPL_RTL_STRNAME( toInt64 )( const IMPL_RTL_STRCODE* pStr, sal_Int16 nRadix ) SAL_THROW_EXTERN_C() { + assert(pStr); return IMPL_RTL_STRNAME( toInt )<sal_Int64, sal_uInt64>(pStr, nRadix); } @@ -1083,6 +1126,7 @@ sal_uInt32 SAL_CALL IMPL_RTL_STRNAME( toUInt32 )( const IMPL_RTL_STRCODE* pStr, sal_Int16 nRadix ) SAL_THROW_EXTERN_C() { + assert(pStr); return IMPL_RTL_STRNAME( toUInt )<sal_uInt32>(pStr, nRadix); } @@ -1090,6 +1134,7 @@ sal_uInt64 SAL_CALL IMPL_RTL_STRNAME( toUInt64 )( const IMPL_RTL_STRCODE* pStr, sal_Int16 nRadix ) SAL_THROW_EXTERN_C() { + assert(pStr); return IMPL_RTL_STRNAME( toUInt )<sal_uInt64>(pStr, nRadix); } @@ -1120,6 +1165,7 @@ static IMPL_RTL_STRCODE* IMPL_RTL_STRINGNAME( ImplNewCopy )( IMPL_RTL_STRINGDATA IMPL_RTL_STRINGDATA* pStr, sal_Int32 nCount ) { + assert(nCount >= 0); IMPL_RTL_STRCODE* pDest; const IMPL_RTL_STRCODE* pSrc; IMPL_RTL_STRINGDATA* pData = IMPL_RTL_STRINGNAME( ImplAlloc )( pStr->length ); @@ -1188,6 +1234,7 @@ void SAL_CALL IMPL_RTL_STRINGNAME( release )( IMPL_RTL_STRINGDATA* pThis ) void SAL_CALL IMPL_RTL_STRINGNAME( new )( IMPL_RTL_STRINGDATA** ppThis ) SAL_THROW_EXTERN_C() { + assert(ppThis); if ( *ppThis) IMPL_RTL_STRINGNAME( release )( *ppThis ); @@ -1210,6 +1257,7 @@ IMPL_RTL_STRINGDATA* SAL_CALL IMPL_RTL_STRINGNAME( alloc )( sal_Int32 nLen ) void SAL_CALL IMPL_RTL_STRINGNAME( new_WithLength )( IMPL_RTL_STRINGDATA** ppThis, sal_Int32 nLen ) SAL_THROW_EXTERN_C() { + assert(ppThis); if ( nLen <= 0 ) IMPL_RTL_STRINGNAME( new )( ppThis ); else @@ -1232,6 +1280,8 @@ void SAL_CALL IMPL_RTL_STRINGNAME( newFromString )( IMPL_RTL_STRINGDATA** ppThis const IMPL_RTL_STRINGDATA* pStr ) SAL_THROW_EXTERN_C() { + assert(ppThis); + assert(pStr); IMPL_RTL_STRINGDATA* pOrg; if ( !pStr->length ) @@ -1257,6 +1307,7 @@ void SAL_CALL IMPL_RTL_STRINGNAME( newFromStr )( IMPL_RTL_STRINGDATA** ppThis, const IMPL_RTL_STRCODE* pCharStr ) SAL_THROW_EXTERN_C() { + assert(ppThis); IMPL_RTL_STRCODE* pBuffer; IMPL_RTL_STRINGDATA* pOrg; sal_Int32 nLen; @@ -1303,6 +1354,7 @@ void SAL_CALL IMPL_RTL_STRINGNAME( newFromStr_WithLength )( IMPL_RTL_STRINGDATA* sal_Int32 nLen ) SAL_THROW_EXTERN_C() { + assert(ppThis); IMPL_RTL_STRINGDATA* pOrg; if ( !pCharStr || (nLen <= 0) ) @@ -1331,6 +1383,7 @@ void SAL_CALL IMPL_RTL_STRINGNAME( newFromSubString )( IMPL_RTL_STRINGDATA** ppT sal_Int32 count ) SAL_THROW_EXTERN_C() { + assert(ppThis); if ( beginIndex == 0 && count == pFrom->length ) { IMPL_RTL_STRINGNAME( assign )( ppThis, const_cast< IMPL_RTL_STRINGDATA * >( pFrom ) ); @@ -1355,6 +1408,9 @@ void SAL_CALL IMPL_RTL_STRINGNAME( newFromLiteral )( IMPL_RTL_STRINGDATA** ppThi sal_Int32 allocExtra ) SAL_THROW_EXTERN_C() { + assert(ppThis); + assert(nLen >= 0); + assert(allocExtra >= 0); if ( nLen + allocExtra == 0 ) { IMPL_RTL_STRINGNAME( new )( ppThis ); @@ -1393,6 +1449,7 @@ void SAL_CALL IMPL_RTL_STRINGNAME( assign )( IMPL_RTL_STRINGDATA** ppThis, IMPL_RTL_STRINGDATA* pStr ) SAL_THROW_EXTERN_C() { + assert(ppThis); /* must be done at first, if pStr == *ppThis */ IMPL_RTL_AQUIRE( pStr ); @@ -1407,6 +1464,7 @@ void SAL_CALL IMPL_RTL_STRINGNAME( assign )( IMPL_RTL_STRINGDATA** ppThis, sal_Int32 SAL_CALL IMPL_RTL_STRINGNAME( getLength )( const IMPL_RTL_STRINGDATA* pThis ) SAL_THROW_EXTERN_C() { + assert(pThis); return pThis->length; } @@ -1415,6 +1473,7 @@ sal_Int32 SAL_CALL IMPL_RTL_STRINGNAME( getLength )( const IMPL_RTL_STRINGDATA* IMPL_RTL_STRCODE* SAL_CALL IMPL_RTL_STRINGNAME( getStr )( IMPL_RTL_STRINGDATA * pThis ) SAL_THROW_EXTERN_C() { + assert(pThis); return pThis->buffer; } @@ -1425,6 +1484,7 @@ void SAL_CALL IMPL_RTL_STRINGNAME( newConcat )( IMPL_RTL_STRINGDATA** ppThis, IMPL_RTL_STRINGDATA* pRight ) SAL_THROW_EXTERN_C() { + assert(ppThis); IMPL_RTL_STRINGDATA* pOrg = *ppThis; /* Test for 0-Pointer - if not, change newReplaceStrAt! */ @@ -1460,6 +1520,7 @@ void SAL_CALL IMPL_RTL_STRINGNAME( ensureCapacity )( IMPL_RTL_STRINGDATA** ppThi sal_Int32 size ) SAL_THROW_EXTERN_C() { + assert(ppThis); IMPL_RTL_STRINGDATA* const pOrg = *ppThis; if ( pOrg->refCount == 1 && pOrg->length >= size ) return; @@ -1484,6 +1545,8 @@ void SAL_CALL IMPL_RTL_STRINGNAME( newReplaceStrAt )( IMPL_RTL_STRINGDATA** ppTh IMPL_RTL_STRINGDATA* pNewSubStr ) SAL_THROW_EXTERN_C() { + assert(ppThis); +// assert(nCount >= 0); /* Append? */ if ( nIndex >= pStr->length ) { @@ -1561,6 +1624,8 @@ void SAL_CALL IMPL_RTL_STRINGNAME( newReplace )( IMPL_RTL_STRINGDATA** ppThis, IMPL_RTL_STRCODE cNew ) SAL_THROW_EXTERN_C() { + assert(ppThis); + assert(pStr); IMPL_RTL_STRINGDATA* pOrg = *ppThis; int bChanged = 0; sal_Int32 nLen = pStr->length; @@ -1620,6 +1685,8 @@ void SAL_CALL IMPL_RTL_STRINGNAME( newToAsciiLowerCase )( IMPL_RTL_STRINGDATA** IMPL_RTL_STRINGDATA* pStr ) SAL_THROW_EXTERN_C() { + assert(ppThis); + assert(pStr); IMPL_RTL_STRINGDATA* pOrg = *ppThis; int bChanged = 0; sal_Int32 nLen = pStr->length; @@ -1676,6 +1743,8 @@ void SAL_CALL IMPL_RTL_STRINGNAME( newToAsciiUpperCase )( IMPL_RTL_STRINGDATA** IMPL_RTL_STRINGDATA* pStr ) SAL_THROW_EXTERN_C() { + assert(ppThis); + assert(pStr); IMPL_RTL_STRINGDATA* pOrg = *ppThis; int bChanged = 0; sal_Int32 nLen = pStr->length; @@ -1732,6 +1801,8 @@ void SAL_CALL IMPL_RTL_STRINGNAME( newTrim )( IMPL_RTL_STRINGDATA** ppThis, IMPL_RTL_STRINGDATA* pStr ) SAL_THROW_EXTERN_C() { + assert(ppThis); + assert(pStr); IMPL_RTL_STRINGDATA* pOrg = *ppThis; const IMPL_RTL_STRCODE* pCharStr = pStr->buffer; sal_Int32 nPreSpaces = 0; @@ -1776,6 +1847,8 @@ sal_Int32 SAL_CALL IMPL_RTL_STRINGNAME( getToken )( IMPL_RTL_STRINGDATA** ppThis sal_Int32 nIndex ) SAL_THROW_EXTERN_C() { + assert(ppThis); + assert(pStr); const IMPL_RTL_STRCODE* pCharStr = pStr->buffer; const IMPL_RTL_STRCODE* pCharStrStart; const IMPL_RTL_STRCODE* pOrgCharStr; diff --git a/sal/rtl/ustrbuf.cxx b/sal/rtl/ustrbuf.cxx index 2ebae71dbaf0..2755ca6f2899 100644 --- a/sal/rtl/ustrbuf.cxx +++ b/sal/rtl/ustrbuf.cxx @@ -33,6 +33,8 @@ void SAL_CALL rtl_uStringbuffer_newFromStr_WithLength( rtl_uString ** newStr, const sal_Unicode * value, sal_Int32 count) { + assert(newStr); + assert(count >= 0); if (!value) { rtl_uString_new_WithLength( newStr, 16 ); @@ -56,6 +58,8 @@ rtl_uString * SAL_CALL rtl_uStringBuffer_refReturn( rtl_uString * pThis ) rtl_uString * SAL_CALL rtl_uStringBuffer_makeStringAndClear( rtl_uString ** ppThis, sal_Int32 *nCapacity ) { + assert(ppThis); + assert(nCapacity); // avoid an un-necessary atomic ref/unref pair rtl_uString *pStr = *ppThis; *ppThis = NULL; @@ -72,6 +76,9 @@ sal_Int32 SAL_CALL rtl_uStringbuffer_newFromStringBuffer( rtl_uString ** newStr, sal_Int32 capacity, rtl_uString * oldStr ) { + assert(newStr); + assert(capacity >= 0); + assert(oldStr); sal_Int32 newCapacity = capacity; if (newCapacity < oldStr->length) @@ -90,6 +97,9 @@ sal_Int32 SAL_CALL rtl_uStringbuffer_newFromStringBuffer( rtl_uString ** newStr, void SAL_CALL rtl_uStringbuffer_ensureCapacity (rtl_uString ** This, sal_Int32* capacity, sal_Int32 minimumCapacity) { + assert(This); + assert(capacity && *capacity >= 0); + assert(minimumCapacity >= 0); if (minimumCapacity > *capacity) { rtl_uString * pTmp = *This; @@ -116,6 +126,11 @@ void SAL_CALL rtl_uStringbuffer_insert( rtl_uString ** This, const sal_Unicode * str, sal_Int32 len) { + assert(This); + assert(capacity && *capacity >= 0); + assert(offset >= 0 && offset <= (**This).length); + assert(len == 0 || str != nullptr); + assert(len >= 0); sal_Int32 nOldLen; sal_Unicode * pBuf; sal_Int32 n; @@ -174,6 +189,11 @@ void SAL_CALL rtl_uStringbuffer_insert_ascii( /*inout*/rtl_uString ** This, const sal_Char * str, sal_Int32 len) { + assert(This); + assert(capacity && *capacity >= 0); + assert(offset >= 0 && offset <= (**This).length); + assert(len == 0 || str != nullptr); + assert(len >= 0); sal_Int32 nOldLen; sal_Unicode * pBuf; sal_Int32 n; @@ -214,6 +234,9 @@ void SAL_CALL rtl_uStringbuffer_remove( rtl_uString ** This, sal_Int32 start, sal_Int32 len ) { + assert(This); + assert(start >= 0 && start <= (**This).length); + assert(len >= 0); sal_Int32 nTailLen; sal_Unicode * pBuf; diff --git a/sal/rtl/ustring.cxx b/sal/rtl/ustring.cxx index 082842523e81..7a342dfdbbb8 100644 --- a/sal/rtl/ustring.cxx +++ b/sal/rtl/ustring.cxx @@ -97,6 +97,8 @@ sal_Int32 rtl_ustr_indexOfAscii_WithLength( sal_Unicode const * str, sal_Int32 len, char const * subStr, sal_Int32 subLen) SAL_THROW_EXTERN_C() { + assert(len >= 0); + assert(subLen >= 0); if (subLen > 0 && subLen <= len) { sal_Int32 i; for (i = 0; i <= len - subLen; ++i) { @@ -114,6 +116,8 @@ sal_Int32 rtl_ustr_lastIndexOfAscii_WithLength( sal_Unicode const * str, sal_Int32 len, char const * subStr, sal_Int32 subLen) SAL_THROW_EXTERN_C() { + assert(len >= 0); + assert(subLen >= 0); if (subLen > 0 && subLen <= len) { sal_Int32 i; for (i = len - subLen; i >= 0; --i) { @@ -130,6 +134,7 @@ sal_Int32 rtl_ustr_lastIndexOfAscii_WithLength( sal_Int32 SAL_CALL rtl_ustr_valueOfFloat(sal_Unicode * pStr, float f) SAL_THROW_EXTERN_C() { + assert(pStr); rtl_uString * pResult = NULL; sal_Int32 nLen; rtl_math_doubleToUString( @@ -146,6 +151,7 @@ sal_Int32 SAL_CALL rtl_ustr_valueOfFloat(sal_Unicode * pStr, float f) sal_Int32 SAL_CALL rtl_ustr_valueOfDouble(sal_Unicode * pStr, double d) SAL_THROW_EXTERN_C() { + assert(pStr); rtl_uString * pResult = NULL; sal_Int32 nLen; rtl_math_doubleToUString( @@ -176,6 +182,7 @@ float doubleToFloat(double x) { float SAL_CALL rtl_ustr_toFloat(sal_Unicode const * pStr) SAL_THROW_EXTERN_C() { + assert(pStr); return doubleToFloat(rtl_math_uStringToDouble(pStr, pStr + rtl_ustr_getLength(pStr), '.', 0, 0, 0)); @@ -183,6 +190,7 @@ float SAL_CALL rtl_ustr_toFloat(sal_Unicode const * pStr) SAL_THROW_EXTERN_C() double SAL_CALL rtl_ustr_toDouble(sal_Unicode const * pStr) SAL_THROW_EXTERN_C() { + assert(pStr); return rtl_math_uStringToDouble(pStr, pStr + rtl_ustr_getLength(pStr), '.', 0, 0, 0); } @@ -193,6 +201,8 @@ sal_Int32 SAL_CALL rtl_ustr_ascii_compare( const sal_Unicode* pStr1, const sal_Char* pStr2 ) SAL_THROW_EXTERN_C() { + assert(pStr1); + assert(pStr2); sal_Int32 nRet; while ( ((nRet = ((sal_Int32)(*pStr1))- ((sal_Int32)((unsigned char)(*pStr2)))) == 0) && @@ -215,6 +225,9 @@ sal_Int32 SAL_CALL rtl_ustr_ascii_compare_WithLength( const sal_Unicode* pStr1, const sal_Char* pStr2 ) SAL_THROW_EXTERN_C() { + assert(pStr1); + assert(nStr1Len >= 0); + assert(pStr2); sal_Int32 nRet = 0; while( ((nRet = (nStr1Len ? (sal_Int32)(*pStr1) : 0)- ((sal_Int32)((unsigned char)(*pStr2)))) == 0) && @@ -239,6 +252,8 @@ sal_Int32 SAL_CALL rtl_ustr_ascii_shortenedCompare_WithLength( const sal_Unicode sal_Int32 nShortenedLength ) SAL_THROW_EXTERN_C() { + assert(nStr1Len >= 0); + assert(nShortenedLength >= 0); const sal_Unicode* pStr1End = pStr1 + nStr1Len; sal_Int32 nRet; while ( (nShortenedLength > 0) && @@ -284,6 +299,7 @@ sal_Int32 SAL_CALL rtl_ustr_asciil_reverseCompare_WithLength( const sal_Unicode* sal_Int32 nStr2Len ) SAL_THROW_EXTERN_C() { + assert(nStr1Len >= 0 && nStr2Len >= 0); const sal_Unicode* pStr1Run = pStr1+nStr1Len; const sal_Char* pStr2Run = pStr2+nStr2Len; sal_Int32 nRet; @@ -309,6 +325,7 @@ sal_Bool SAL_CALL rtl_ustr_asciil_reverseEquals_WithLength( const sal_Unicode* p sal_Int32 nStrLen ) SAL_THROW_EXTERN_C() { + assert(nStrLen >= 0); const sal_Unicode* pStr1Run = pStr1+nStrLen; const sal_Char* pStr2Run = pStr2+nStrLen; while ( pStr1 < pStr1Run ) @@ -331,6 +348,8 @@ sal_Int32 SAL_CALL rtl_ustr_ascii_compareIgnoreAsciiCase( const sal_Unicode* pSt const sal_Char* pStr2 ) SAL_THROW_EXTERN_C() { + assert(pStr1); + assert(pStr2); sal_Int32 nRet; sal_Int32 c1; sal_Int32 c2; @@ -365,6 +384,8 @@ sal_Int32 SAL_CALL rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( const sal_U const sal_Char* pStr2 ) SAL_THROW_EXTERN_C() { + assert(nStr1Len >= 0); + assert(pStr2); sal_Int32 nRet; sal_Int32 c1; sal_Int32 c2; @@ -400,6 +421,7 @@ sal_Int32 rtl_ustr_ascii_compareIgnoreAsciiCase_WithLengths( sal_Unicode const * first, sal_Int32 firstLen, char const * second, sal_Int32 secondLen) SAL_THROW_EXTERN_C() { + assert(firstLen >= 0 && secondLen >= 0); sal_Int32 i; sal_Int32 len = firstLen < secondLen ? firstLen : secondLen; for (i = 0; i < len; ++i) { @@ -431,6 +453,8 @@ sal_Int32 SAL_CALL rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength( co sal_Int32 nShortenedLength ) SAL_THROW_EXTERN_C() { + assert(nStr1Len >= 0); + assert(nShortenedLength >= 0); const sal_Unicode* pStr1End = pStr1 + nStr1Len; sal_Int32 nRet; sal_Int32 c1; @@ -482,6 +506,7 @@ void SAL_CALL rtl_uString_newFromAscii( rtl_uString** ppThis, const sal_Char* pCharStr ) SAL_THROW_EXTERN_C() { + assert(ppThis); sal_Int32 nLen; if ( pCharStr ) @@ -528,10 +553,8 @@ void SAL_CALL rtl_uString_newFromCodePoints( sal_Int32 n; sal_Int32 i; sal_Unicode * p; - OSL_ASSERT( - newString != NULL && - (codePoints != NULL || codePointCount == 0) && - codePointCount >= 0); + assert(newString != nullptr); + assert((codePoints != nullptr || codePointCount == 0) && codePointCount >= 0); if (codePointCount == 0) { rtl_uString_new(newString); return; @@ -801,6 +824,8 @@ void SAL_CALL rtl_string2UString( rtl_uString** ppThis, rtl_TextEncoding eTextEncoding, sal_uInt32 nCvtFlags ) SAL_THROW_EXTERN_C() { + assert(ppThis); + assert(nLen >= 0); rtl_string2UString_status( ppThis, pStr, nLen, eTextEncoding, nCvtFlags, NULL ); } @@ -863,6 +888,8 @@ static void rtl_ustring_intern_internal( rtl_uString ** newStr, void SAL_CALL rtl_uString_intern( rtl_uString ** newStr, rtl_uString * str) SAL_THROW_EXTERN_C() { + assert(newStr); + assert(str); if (SAL_STRING_IS_INTERN(str)) { IMPL_RTL_AQUIRE( str ); @@ -909,6 +936,8 @@ void SAL_CALL rtl_uString_internConvert( rtl_uString ** newStr, sal_uInt32 * pInfo ) SAL_THROW_EXTERN_C() { + assert(newStr); + assert(len >= 0); rtl_uString *scratch; if (*newStr) @@ -1056,6 +1085,8 @@ sal_Bool rtl_convertStringToUString( rtl_uString ** target, char const * source, sal_Int32 length, rtl_TextEncoding encoding, sal_uInt32 flags) SAL_THROW_EXTERN_C() { + assert(target); + assert(length >= 0); sal_uInt32 info; rtl_string2UString_status(target, source, length, encoding, flags, &info); return (info & RTL_TEXTTOUNICODE_INFO_ERROR) == 0; |