summaryrefslogtreecommitdiff
path: root/sal/rtl/strtmpl.cxx
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2018-07-31 16:00:02 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2018-08-02 11:07:55 +0200
commit2f3684b2289a8c46dc6144064a452cc529400f28 (patch)
treefc460328cc6963b9a156c23395ce8f15c70e878d /sal/rtl/strtmpl.cxx
parent4804a1474ccba8df57f0a0151bd69237e82eb618 (diff)
[API CHANGE] add some more asserts to the string functions
rtl_[u]String_alloc now requires that the length be >= 0. Since this function is only @since Libreoffice 4.1, it is unlikely to be widely used externally. Removed some unit tests that were testing invalid or out of range paramers, which are already not allowed according to the documented contract of those functions. The change in writerfilter is because the new asserts triggered when running testFdo74745 The change in SwTextNode::EraseText is because testFdo60842 triggered the assert in replaceAt. The change in SwFieldSlot::SwFieldSlot is because testMoveRange::Import_Export_Import triggered the assert in replaceAt. The changes in SwFieldSlot::SwFieldSlot and TabControl::ImplGetItemSize are due to failures in the uitests. Change-Id: Ib317261067649b0de96df12873ce31360cd24681 Reviewed-on: https://gerrit.libreoffice.org/58390 Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk> Tested-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sal/rtl/strtmpl.cxx')
-rw-r--r--sal/rtl/strtmpl.cxx19
1 files changed, 13 insertions, 6 deletions
diff --git a/sal/rtl/strtmpl.cxx b/sal/rtl/strtmpl.cxx
index c4f8fa605efa..e4ccb80b68f4 100644
--- a/sal/rtl/strtmpl.cxx
+++ b/sal/rtl/strtmpl.cxx
@@ -562,7 +562,7 @@ sal_Int32 SAL_CALL IMPL_RTL_STRNAME( lastIndexOfStr_WithLength )( const IMPL_RTL
sal_Int32 nSubLen )
SAL_THROW_EXTERN_C()
{
-// assert(nStrLen >= 0);
+ assert(nStrLen >= 0);
assert(nSubLen >= 0);
/* faster search for a single character */
if ( nSubLen < 2 )
@@ -809,6 +809,7 @@ sal_Int32 SAL_CALL IMPL_RTL_STRNAME( valueOfInt32 )( IMPL_RTL_STRCODE* pStr,
SAL_THROW_EXTERN_C()
{
assert(pStr);
+ assert( nRadix >= RTL_STR_MIN_RADIX && nRadix <= RTL_STR_MAX_RADIX );
sal_Char aBuf[RTL_STR_MAX_VALUEOFINT32];
sal_Char* pBuf = aBuf;
sal_Int32 nLen = 0;
@@ -864,6 +865,7 @@ sal_Int32 SAL_CALL IMPL_RTL_STRNAME( valueOfInt64 )( IMPL_RTL_STRCODE* pStr,
SAL_THROW_EXTERN_C()
{
assert(pStr);
+ assert( nRadix >= RTL_STR_MIN_RADIX && nRadix <= RTL_STR_MAX_RADIX );
sal_Char aBuf[RTL_STR_MAX_VALUEOFINT64];
sal_Char* pBuf = aBuf;
sal_Int32 nLen = 0;
@@ -919,6 +921,7 @@ sal_Int32 SAL_CALL IMPL_RTL_STRNAME( valueOfUInt64 )( IMPL_RTL_STRCODE* pStr,
SAL_THROW_EXTERN_C()
{
assert(pStr);
+ assert( nRadix >= RTL_STR_MIN_RADIX && nRadix <= RTL_STR_MAX_RADIX );
sal_Char aBuf[RTL_STR_MAX_VALUEOFUINT64];
sal_Char* pBuf = aBuf;
sal_Int32 nLen = 0;
@@ -990,6 +993,7 @@ namespace {
sal_Int16 nRadix )
{
static_assert(std::numeric_limits<T>::is_signed, "is signed");
+ assert( nRadix >= RTL_STR_MIN_RADIX && nRadix <= RTL_STR_MAX_RADIX );
bool bNeg;
sal_Int16 nDigit;
U n = 0;
@@ -1080,6 +1084,7 @@ namespace {
sal_Int16 nRadix )
{
static_assert(!std::numeric_limits<T>::is_signed, "is not signed");
+ assert( nRadix >= RTL_STR_MIN_RADIX && nRadix <= RTL_STR_MAX_RADIX );
sal_Int16 nDigit;
T n = 0;
@@ -1237,10 +1242,8 @@ void SAL_CALL IMPL_RTL_STRINGNAME( new )( IMPL_RTL_STRINGDATA** ppThis )
IMPL_RTL_STRINGDATA* SAL_CALL IMPL_RTL_STRINGNAME( alloc )( sal_Int32 nLen )
SAL_THROW_EXTERN_C()
{
- if ( nLen < 0 )
- return nullptr;
- else
- return IMPL_RTL_STRINGNAME( ImplAlloc )( nLen );
+ assert(nLen >= 0);
+ return IMPL_RTL_STRINGNAME( ImplAlloc )( nLen );
}
/* ----------------------------------------------------------------------- */
@@ -1249,6 +1252,7 @@ void SAL_CALL IMPL_RTL_STRINGNAME( new_WithLength )( IMPL_RTL_STRINGDATA** ppThi
SAL_THROW_EXTERN_C()
{
assert(ppThis);
+ assert(nLen >= 0);
if ( nLen <= 0 )
IMPL_RTL_STRINGNAME( new )( ppThis );
else
@@ -1334,6 +1338,7 @@ void SAL_CALL IMPL_RTL_STRINGNAME( newFromStr_WithLength )( IMPL_RTL_STRINGDATA*
SAL_THROW_EXTERN_C()
{
assert(ppThis);
+ assert(nLen >= 0);
IMPL_RTL_STRINGDATA* pOrg;
if ( !pCharStr || (nLen <= 0) )
@@ -1532,7 +1537,9 @@ void SAL_CALL IMPL_RTL_STRINGNAME( newReplaceStrAt )( IMPL_RTL_STRINGDATA** ppTh
SAL_THROW_EXTERN_C()
{
assert(ppThis);
-// assert(nCount >= 0);
+ assert(nIndex >= 0 && nIndex <= pStr->length);
+ assert(nCount >= 0);
+ assert(nCount <= pStr->length - nIndex);
/* Append? */
if ( nIndex >= pStr->length )
{