From b0ef5cf258f3a84054c052f0a09a208dbc17fdf3 Mon Sep 17 00:00:00 2001 From: Michael Stahl Date: Thu, 5 Feb 2015 22:07:28 +0100 Subject: 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 --- sal/rtl/strbuf.cxx | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'sal/rtl/strbuf.cxx') 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; -- cgit