summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/rtl/strbuf.h4
-rw-r--r--include/rtl/strbuf.hxx24
-rw-r--r--sal/rtl/math.cxx2
-rw-r--r--sal/rtl/strbuf.cxx11
4 files changed, 36 insertions, 5 deletions
diff --git a/include/rtl/strbuf.h b/include/rtl/strbuf.h
index 403d53c0b895..3f682db37615 100644
--- a/include/rtl/strbuf.h
+++ b/include/rtl/strbuf.h
@@ -101,7 +101,9 @@ SAL_DLLPUBLIC void SAL_CALL rtl_stringbuffer_ensureCapacity(
@param[in,out] This the String to operate on.
@param[in,out] capacity the capacity of the string buffer
@param[in] offset the offset.
- @param[in] str a character array.
+ @param[in] str a character array. Since LibreOffice 4.4, as a
+ special case, if str is null then the len added
+ characters are left uninitialized.
@param[in] len the number of characters to append.
*/
SAL_DLLPUBLIC void SAL_CALL rtl_stringbuffer_insert(
diff --git a/include/rtl/strbuf.hxx b/include/rtl/strbuf.hxx
index c089d61d48ad..b135298e1ced 100644
--- a/include/rtl/strbuf.hxx
+++ b/include/rtl/strbuf.hxx
@@ -490,6 +490,7 @@ public:
OStringBuffer & append( const sal_Char * str, sal_Int32 len)
{
assert( len >= 0 );
+ assert( len == 0 || str != 0 );
rtl_stringbuffer_insert( &pData, &nCapacity, getLength(), str, len );
return *this;
}
@@ -645,6 +646,28 @@ public:
}
/**
+ Unsafe way to make space for a fixed amount of characters to be appended
+ into this OStringBuffer.
+
+ A call to this function must immediately be followed by code that
+ completely fills the uninitialized block pointed to by the return value.
+
+ @param length the length of the uninitialized block of char entities;
+ must be non-negative
+
+ @return a pointer to the start of the uninitialized block; only valid
+ until this OStringBuffer's capacity changes
+
+ @since LibreOffice 4.4
+ */
+ char * appendUninitialized(sal_Int32 length) {
+ assert(length >= 0);
+ sal_Int32 n = getLength();
+ rtl_stringbuffer_insert(&pData, &nCapacity, n, 0, length);
+ return pData->buffer + n;
+ }
+
+ /**
Inserts the string into this string buffer.
The characters of the <code>String</code> argument are inserted, in
@@ -729,6 +752,7 @@ public:
{
assert( offset >= 0 && offset <= pData->length );
assert( len >= 0 );
+ assert( len == 0 || str != 0 );
rtl_stringbuffer_insert( &pData, &nCapacity, offset, str, len );
return *this;
}
diff --git a/sal/rtl/math.cxx b/sal/rtl/math.cxx
index ac5a79387617..d74f5020bc1a 100644
--- a/sal/rtl/math.cxx
+++ b/sal/rtl/math.cxx
@@ -222,6 +222,7 @@ struct StringTraits
sal_Int32 * pOffset, sal_Char const * pChars,
sal_Int32 nLen)
{
+ assert(pChars != nullptr);
rtl_stringbuffer_insert(pBuffer, pCapacity, *pOffset, pChars, nLen);
*pOffset += nLen;
}
@@ -230,6 +231,7 @@ struct StringTraits
sal_Int32 * pOffset, sal_Char const * pStr,
sal_Int32 nLen)
{
+ assert(pStr != nullptr);
rtl_stringbuffer_insert(pBuffer, pCapacity, *pOffset, pStr, nLen);
*pOffset += nLen;
}
diff --git a/sal/rtl/strbuf.cxx b/sal/rtl/strbuf.cxx
index f8b1f9c6df8c..f75d0cc7ef57 100644
--- a/sal/rtl/strbuf.cxx
+++ b/sal/rtl/strbuf.cxx
@@ -114,11 +114,14 @@ void SAL_CALL rtl_stringbuffer_insert( rtl_String ** This,
memmove( pBuf + offset + len, pBuf + offset, n * sizeof(sal_Char) );
/* insert the new characters */
- if( len == 1 )
+ if( str != nullptr )
+ {
+ if( len == 1 )
/* optimized for 1 character */
- pBuf[offset] = *str;
- else
- memcpy( pBuf + offset, str, len * sizeof(sal_Char) );
+ pBuf[offset] = *str;
+ else
+ memcpy( pBuf + offset, str, len * sizeof(sal_Char) );
+ }
(*This)->length = nOldLen + len;
pBuf[ nOldLen + len ] = 0;
}