[Libreoffice-commits] core.git: include/rtl sal/qa sal/rtl sw/source vcl/source writerfilter/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Thu Aug 2 09:08:23 UTC 2018


 include/rtl/string.h                              |    5 
 include/rtl/ustring.h                             |    5 
 sal/qa/OStringBuffer/rtl_OStringBuffer.cxx        |  378 ----------------------
 sal/qa/rtl/oustring/rtl_OUString2.cxx             |    2 
 sal/rtl/strtmpl.cxx                               |   19 -
 sw/source/core/text/porfld.cxx                    |    2 
 sw/source/core/txtnode/ndtxt.cxx                  |    3 
 vcl/source/control/tabctrl.cxx                    |    3 
 writerfilter/source/dmapper/DomainMapper_Impl.cxx |   12 
 9 files changed, 34 insertions(+), 395 deletions(-)

New commits:
commit 2f3684b2289a8c46dc6144064a452cc529400f28
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Tue Jul 31 16:00:02 2018 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Thu Aug 2 11:07:55 2018 +0200

    [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 at collabora.co.uk>
    Tested-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/include/rtl/string.h b/include/rtl/string.h
index ecf4704b0999..17ab629005b3 100644
--- a/include/rtl/string.h
+++ b/include/rtl/string.h
@@ -886,7 +886,7 @@ SAL_DLLPUBLIC void SAL_CALL rtl_string_new( rtl_String ** newStr ) SAL_THROW_EXT
     The reference count of the new string will be 1. The length of the string
     will be nLen. This function does not handle out-of-memory conditions.
 
-    For nLen < 0 or failed allocation this method returns NULL.
+    For failed allocation this method returns NULL.
 
     The characters of the capacity are not cleared, and the length is set to
     nLen, unlike the similar method of rtl_String_new_WithLength which
@@ -897,7 +897,8 @@ SAL_DLLPUBLIC void SAL_CALL rtl_string_new( rtl_String ** newStr ) SAL_THROW_EXT
     alternatively pass ownership to an OUString with
     rtl::OUString(newStr, SAL_NO_ACQUIRE);
 
-    @param[out] nLen the number of characters.
+    @param[out] nLen the number of characters. Must be >= 0.
+
     @return pointer to the new string.
 
     @since LibreOffice 4.1
diff --git a/include/rtl/ustring.h b/include/rtl/ustring.h
index e46e646c9c71..cd6f75e889db 100644
--- a/include/rtl/ustring.h
+++ b/include/rtl/ustring.h
@@ -1219,7 +1219,7 @@ SAL_DLLPUBLIC void SAL_CALL rtl_uString_new(
     The reference count of the new string will be 1. The length of the string
     will be nLen. This function does not handle out-of-memory conditions.
 
-    For nLen < 0 or failed allocation this method returns NULL.
+    For failed allocation this method returns NULL.
 
     The characters of the capacity are not cleared, and the length is set to
     nLen, unlike the similar method of rtl_uString_new_WithLength which
@@ -1230,7 +1230,8 @@ SAL_DLLPUBLIC void SAL_CALL rtl_uString_new(
     alternatively pass ownership to an OUString with
     rtl::OUString(newStr, SAL_NO_ACQUIRE);
 
-    @param[in] nLen the number of characters.
+    @param[in] nLen the number of characters. Must be >= 0.
+
     @return pointer to the new string.
 
     @since LibreOffice 4.1
diff --git a/sal/qa/OStringBuffer/rtl_OStringBuffer.cxx b/sal/qa/OStringBuffer/rtl_OStringBuffer.cxx
index 3afd07f8dcab..46ed91ecfa99 100644
--- a/sal/qa/OStringBuffer/rtl_OStringBuffer.cxx
+++ b/sal/qa/OStringBuffer/rtl_OStringBuffer.cxx
@@ -34,7 +34,6 @@ using ::rtl::OString;
 // OString and OStringBuffer classes
 
 // testing constructors
-
 namespace rtl_OStringBuffer
 {
     class  ctors : public CppUnit::TestFixture
@@ -134,31 +133,6 @@ namespace rtl_OStringBuffer
 
         }
 
-        void ctor_003_1()
-        {
-            // StringBuffer with created negative size are the
-            // same as empty StringBuffers
-            ::rtl::OStringBuffer aStrBuf3(kNonSInt32Max);
-
-            const sal_Char* pStr = aStrBuf3.getStr();
-
-            CPPUNIT_ASSERT_MESSAGE
-            (
-                "New OStringBuffer containing no characters and contain assigned capacity",
-                aStrBuf3.isEmpty()
-            );
-            CPPUNIT_ASSERT_EQUAL_MESSAGE
-            (
-                "New OStringBuffer containing no characters and contain assigned capacity",
-                '\0', *pStr
-            );
-            CPPUNIT_ASSERT_EQUAL_MESSAGE
-            (
-                "New OStringBuffer containing no characters and contain assigned capacity",
-                kNonSInt32Max, aStrBuf3.getCapacity()
-            );
-        }
-
         void ctor_004()
         {
             ::rtl::OString aStrtmp( kTestStr1 );
@@ -214,7 +188,6 @@ namespace rtl_OStringBuffer
         CPPUNIT_TEST(ctor_001);
         CPPUNIT_TEST(ctor_002);
         CPPUNIT_TEST(ctor_003);
-        CPPUNIT_TEST(ctor_003_1);
         CPPUNIT_TEST(ctor_004);
         CPPUNIT_TEST(ctor_005);
         CPPUNIT_TEST(ctor_006);
@@ -662,18 +635,6 @@ namespace rtl_OStringBuffer
             );
         }
 
-        void getCapacity_009()
-        {
-            ::rtl::OStringBuffer   aStrBuf( kNonSInt32Max );
-            sal_Int32              expVal = kNonSInt32Max;
-
-            CPPUNIT_ASSERT_EQUAL_MESSAGE
-            (
-                "capacity of empty string (with capacity -2147483648)",
-                expVal, aStrBuf.getCapacity()
-            );
-        }
-
         void getCapacity_010()
         {
             ::rtl::OStringBuffer   aStrBuf( 16 );
@@ -710,18 +671,6 @@ namespace rtl_OStringBuffer
             );
         }
 
-        void getCapacity_013()
-        {
-            ::rtl::OStringBuffer   aStrBuf( -2 );
-            sal_Int32              expVal = -2;
-
-            CPPUNIT_ASSERT_EQUAL_MESSAGE
-            (
-                "capacity of empty string (with capacity -2)",
-                expVal, aStrBuf.getCapacity()
-            );
-        }
-
         CPPUNIT_TEST_SUITE( getCapacity );
         CPPUNIT_TEST( getCapacity_001 );
         CPPUNIT_TEST( getCapacity_002 );
@@ -730,11 +679,9 @@ namespace rtl_OStringBuffer
         CPPUNIT_TEST( getCapacity_005 );
         CPPUNIT_TEST( getCapacity_006 );
         CPPUNIT_TEST( getCapacity_007 );
-        CPPUNIT_TEST( getCapacity_009 );
         CPPUNIT_TEST( getCapacity_010 );
         CPPUNIT_TEST( getCapacity_011 );
         CPPUNIT_TEST( getCapacity_012 );
-        CPPUNIT_TEST( getCapacity_013 );
         CPPUNIT_TEST_SUITE_END();
     };
 
@@ -932,70 +879,6 @@ namespace rtl_OStringBuffer
 
         }
 
-        void ensureCapacity_018()
-        {
-            sal_Int32          expVal = 65535;
-            ::rtl::OStringBuffer   aStrBuf( kNonSInt32Max );
-            sal_Int32              input = 65535;
-
-            aStrBuf.ensureCapacity( input );
-
-            CPPUNIT_ASSERT_EQUAL_MESSAGE
-            (
-                "capacity equal to -2147483648, minimum is 65535",
-                expVal, aStrBuf.getCapacity()
-            );
-
-        }
-
-        void ensureCapacity_020()
-        {
-            sal_Int32          expVal = 2;
-            ::rtl::OStringBuffer   aStrBuf( kNonSInt32Max );
-            sal_Int32              input = -1;
-
-            aStrBuf.ensureCapacity( input );
-
-            CPPUNIT_ASSERT_EQUAL_MESSAGE
-            (
-                "capacity equal to -2147483648, minimum is -1",
-                expVal, aStrBuf.getCapacity()
-            );
-
-        }
-
-        void ensureCapacity_021()
-        {
-            sal_Int32          expVal = 2;
-            ::rtl::OStringBuffer   aStrBuf( kNonSInt32Max );
-            sal_Int32              input = 0;
-
-            aStrBuf.ensureCapacity( input );
-
-            CPPUNIT_ASSERT_EQUAL_MESSAGE
-            (
-                "capacity equal to -2147483648, minimum is 0",
-                expVal, aStrBuf.getCapacity()
-            );
-
-        }
-
-        void ensureCapacity_022()
-        {
-            sal_Int32          expVal = kNonSInt32Max;
-            ::rtl::OStringBuffer   aStrBuf( kNonSInt32Max );
-            sal_Int32              input = kNonSInt32Max;
-
-            aStrBuf.ensureCapacity( input );
-
-            CPPUNIT_ASSERT_EQUAL_MESSAGE
-            (
-                "capacity equal to -2147483648, minimum is -2147483648",
-                expVal, aStrBuf.getCapacity()
-            );
-
-        }
-
         CPPUNIT_TEST_SUITE( ensureCapacity );
         CPPUNIT_TEST( ensureCapacity_001 );
         CPPUNIT_TEST( ensureCapacity_002 );
@@ -1009,10 +892,6 @@ namespace rtl_OStringBuffer
         CPPUNIT_TEST( ensureCapacity_010 );
         CPPUNIT_TEST( ensureCapacity_011 );
         CPPUNIT_TEST( ensureCapacity_012 );
-        CPPUNIT_TEST( ensureCapacity_018 );
-        CPPUNIT_TEST( ensureCapacity_020 );
-        CPPUNIT_TEST( ensureCapacity_021 );
-        CPPUNIT_TEST( ensureCapacity_022 );
         CPPUNIT_TEST_SUITE_END();
     };
 
@@ -8276,135 +8155,6 @@ namespace rtl_OStringBuffer
         CPPUNIT_TEST_SUITE_END();
     };
 
-// testing the method append( sal_Int32 i, sal_Int16 radix ) where radix = -5
-
-    class  append_006_Int32_WrongRadix : public CppUnit::TestFixture
-    {
-        OString* arrOUS[5];
-        static const sal_Int32 intVal = 11;
-
-    public:
-        void setUp() override
-        {
-            arrOUS[0] = new OString( kTestStr7 );
-            arrOUS[1] = new OString(  );
-            arrOUS[2] = new OString( kTestStr25 );
-            arrOUS[3] = new OString( "" );
-            arrOUS[4] = new OString( kTestStr28 );
-        }
-
-        void tearDown() override
-        {
-            delete arrOUS[0]; delete arrOUS[1]; delete arrOUS[2];
-            delete arrOUS[3]; delete arrOUS[4];
-        }
-
-        void append_001()
-        {
-            ::rtl::OStringBuffer   aStrBuf( *arrOUS[0] );
-            OString                expVal( kTestStr59 );
-
-            aStrBuf.append( intVal, -5 );
-
-            CPPUNIT_ASSERT_MESSAGE
-            (
-                "Appends the WrongRadix to the string buffer arrOUS[0]",
-                aStrBuf.getStr()== expVal &&
-                    aStrBuf.getLength() == expVal.getLength()
-            );
-        }
-
-        void append_002()
-        {
-            ::rtl::OStringBuffer   aStrBuf( *arrOUS[1] );
-            OString                expVal( kTestStr60 );
-
-            aStrBuf.append( intVal, -5 );
-
-            CPPUNIT_ASSERT_MESSAGE
-            (
-                "Appends the WrongRadix to the string buffer arrOUS[1]",
-                aStrBuf.getStr()== expVal &&
-                    aStrBuf.getLength() == expVal.getLength()
-            );
-        }
-
-        void append_003()
-        {
-            ::rtl::OStringBuffer   aStrBuf( *arrOUS[2] );
-            OString                expVal( kTestStr60 );
-
-            aStrBuf.append( intVal, -5 );
-
-            CPPUNIT_ASSERT_MESSAGE
-            (
-                "Appends the WrongRadix to the string buffer arrOUS[2]",
-                aStrBuf.getStr()== expVal &&
-                    aStrBuf.getLength() == expVal.getLength()
-            );
-
-        }
-
-        void append_004()
-        {
-            ::rtl::OStringBuffer   aStrBuf( *arrOUS[3] );
-            OString                expVal( kTestStr60 );
-
-            aStrBuf.append( intVal, -5 );
-
-            CPPUNIT_ASSERT_MESSAGE
-            (
-                "Appends the WrongRadix to the string buffer arrOUS[3]",
-                aStrBuf.getStr()== expVal &&
-                    aStrBuf.getLength() == expVal.getLength()
-            );
-
-        }
-
-        void append_005()
-        {
-            ::rtl::OStringBuffer   aStrBuf( *arrOUS[4] );
-            OString                expVal( kTestStr61 );
-
-            aStrBuf.append( intVal, -5 );
-
-            CPPUNIT_ASSERT_MESSAGE
-            (
-                "Appends the WrongRadix to the string buffer arrOUS[4]",
-                (aStrBuf.toString() == expVal &&
-                 aStrBuf.getLength() == expVal.getLength())
-            );
-        }
-#ifdef WITH_CORE
-        void append_006()
-        {
-            ::rtl::OStringBuffer   aStrBuf( kSInt32Max );
-            OString                expVal( kTestStr60 );
-
-            aStrBuf.append( intVal, -5 );
-
-            CPPUNIT_ASSERT_MESSAGE
-            (
-                "Appends the WrongRadix to the string buffer(with INT_MAX)",
-                aStrBuf.getStr()== expVal &&
-                    aStrBuf.getLength() == expVal.getLength()
-            );
-
-        }
-#endif
-
-        CPPUNIT_TEST_SUITE( append_006_Int32_WrongRadix );
-        CPPUNIT_TEST( append_001 );
-        CPPUNIT_TEST( append_002 );
-        CPPUNIT_TEST( append_003 );
-        CPPUNIT_TEST( append_004 );
-        CPPUNIT_TEST( append_005 );
-#ifdef WITH_CORE
-        CPPUNIT_TEST( append_006 );
-#endif
-        CPPUNIT_TEST_SUITE_END();
-    };
-
     class  append_006_Int32_defaultParam : public CppUnit::TestFixture
     {
         OString* arrOUS[5];
@@ -14026,132 +13776,6 @@ namespace rtl_OStringBuffer
         CPPUNIT_TEST_SUITE_END();
     };
 
-// testing the method append( sal_Int64 i, sal_Int16 radix ) where radix = -5
-
-    class  append_007_Int64_WrongRadix : public CppUnit::TestFixture
-    {
-        OString* arrOUS[5];
-        static const sal_Int64 intVal = 11;
-
-    public:
-        void setUp() override
-        {
-            arrOUS[0] = new OString( kTestStr7 );
-            arrOUS[1] = new OString(  );
-            arrOUS[2] = new OString( kTestStr25 );
-            arrOUS[3] = new OString( "" );
-            arrOUS[4] = new OString( kTestStr28 );
-        }
-
-        void tearDown() override
-        {
-            delete arrOUS[0]; delete arrOUS[1]; delete arrOUS[2];
-            delete arrOUS[3]; delete arrOUS[4];
-        }
-
-        void append_001()
-        {
-            ::rtl::OStringBuffer   aStrBuf( *arrOUS[0] );
-            OString                expVal( kTestStr59 );
-
-            aStrBuf.append( intVal, -5 );
-
-            CPPUNIT_ASSERT_MESSAGE
-            (
-                "Appends the WrongRadix to the string buffer arrOUS[0]",
-                (aStrBuf.toString() == expVal &&
-                 aStrBuf.getLength() == expVal.getLength())
-            );
-        }
-
-        void append_002()
-        {
-            ::rtl::OStringBuffer   aStrBuf( *arrOUS[1] );
-            OString                expVal( kTestStr60 );
-
-            aStrBuf.append( intVal, -5 );
-
-            CPPUNIT_ASSERT_MESSAGE
-            (
-                "Appends the WrongRadix to the string buffer arrOUS[1]",
-                (aStrBuf.toString() == expVal &&
-                 aStrBuf.getLength() == expVal.getLength())
-            );
-        }
-
-        void append_003()
-        {
-            ::rtl::OStringBuffer   aStrBuf( *arrOUS[2] );
-            OString                expVal( kTestStr60 );
-
-            aStrBuf.append( intVal, -5 );
-
-            CPPUNIT_ASSERT_MESSAGE
-            (
-                "Appends the WrongRadix to the string buffer arrOUS[2]",
-                (aStrBuf.toString() == expVal &&
-                 aStrBuf.getLength() == expVal.getLength())
-            );
-        }
-
-        void append_004()
-        {
-            ::rtl::OStringBuffer   aStrBuf( *arrOUS[3] );
-            OString                expVal( kTestStr60 );
-
-            aStrBuf.append( intVal, -5 );
-
-            CPPUNIT_ASSERT_MESSAGE
-            (
-                "Appends the WrongRadix to the string buffer arrOUS[3]",
-                (aStrBuf.toString() == expVal &&
-                 aStrBuf.getLength() == expVal.getLength())
-            );
-        }
-
-        void append_005()
-        {
-            ::rtl::OStringBuffer   aStrBuf( *arrOUS[4] );
-            OString                expVal( kTestStr61 );
-
-            aStrBuf.append( intVal, -5 );
-
-            CPPUNIT_ASSERT_MESSAGE
-            (
-                "Appends the WrongRadix to the string buffer arrOUS[4]",
-                (aStrBuf.toString() == expVal &&
-                 aStrBuf.getLength() == expVal.getLength())
-            );
-        }
-#ifdef WITH_CORE
-        void append_006()
-        {
-            ::rtl::OStringBuffer   aStrBuf( kSInt64Max );
-            OString                expVal( kTestStr60 );
-
-            aStrBuf.append( intVal, -5 );
-
-            CPPUNIT_ASSERT_MESSAGE
-            (
-                "Appends the WrongRadix to the string buffer(with INT_MAX)",
-                (aStrBuf.toString() == expVal &&
-                 aStrBuf.getLength() == expVal.getLength())
-            );
-        }
-#endif
-
-        CPPUNIT_TEST_SUITE( append_007_Int64_WrongRadix );
-        CPPUNIT_TEST( append_001 );
-        CPPUNIT_TEST( append_002 );
-        CPPUNIT_TEST( append_003 );
-        CPPUNIT_TEST( append_004 );
-        CPPUNIT_TEST( append_005 );
-#ifdef WITH_CORE
-        CPPUNIT_TEST( append_006 );
-#endif
-        CPPUNIT_TEST_SUITE_END();
-    };
-
     class  append_007_Int64_defaultParam : public CppUnit::TestFixture
     {
         OString* arrOUS[5];
@@ -16076,12 +15700,10 @@ CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OStringBuffer::append_005);
 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OStringBuffer::append_006_Int32);
 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OStringBuffer::append_006_Int32_Bounderies);
 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OStringBuffer::append_006_Int32_Negative);
-CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OStringBuffer::append_006_Int32_WrongRadix);
 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OStringBuffer::append_006_Int32_defaultParam);
 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OStringBuffer::append_007_Int64);
 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OStringBuffer::append_007_Int64_Bounderies);
 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OStringBuffer::append_007_Int64_Negative);
-CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OStringBuffer::append_007_Int64_WrongRadix);
 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OStringBuffer::append_007_Int64_defaultParam);
 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OStringBuffer::append_008_float);
 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OStringBuffer::append_008_Float_Negative);
diff --git a/sal/qa/rtl/oustring/rtl_OUString2.cxx b/sal/qa/rtl/oustring/rtl_OUString2.cxx
index 426834b88f5f..7dce206300a2 100644
--- a/sal/qa/rtl/oustring/rtl_OUString2.cxx
+++ b/sal/qa/rtl/oustring/rtl_OUString2.cxx
@@ -584,7 +584,7 @@ public:
             // search for sun, start at the end, found (pos==0)
             rtl::OUString aStr("sun java system");
             rtl::OUString aSearchStr("sun");
-            lastIndexOf_oustring_offset(aStr, aSearchStr, -1, -1);
+            lastIndexOf_oustring_offset(aStr, aSearchStr, -1, 1);
         }
 
     void lastIndexOf_test_oustring_001()
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 )
     {
diff --git a/sw/source/core/text/porfld.cxx b/sw/source/core/text/porfld.cxx
index a3cb46ea7f68..d76a1d94c053 100644
--- a/sw/source/core/text/porfld.cxx
+++ b/sw/source/core/text/porfld.cxx
@@ -171,7 +171,7 @@ SwFieldSlot::SwFieldSlot( const SwTextFormatInfo* pNew, const SwFieldPortion *pP
             pInf->SetFakeLineStart( nIdx > pInf->GetLineStart() );
             pInf->SetIdx(TextFrameIndex(0));
         }
-        else
+        else if(nIdx < pOldText->getLength())
         {
             aText = (*pOldText).replaceAt(sal_Int32(nIdx), 1, aText);
         }
diff --git a/sw/source/core/txtnode/ndtxt.cxx b/sw/source/core/txtnode/ndtxt.cxx
index e8106bb859fe..4f1b12610b1b 100644
--- a/sw/source/core/txtnode/ndtxt.cxx
+++ b/sw/source/core/txtnode/ndtxt.cxx
@@ -2344,7 +2344,8 @@ void SwTextNode::EraseText(const SwIndex &rIdx, const sal_Int32 nCount,
     const sal_Int32 nCnt = (nCount==SAL_MAX_INT32)
                       ? m_Text.getLength() - nStartIdx : nCount;
     const sal_Int32 nEndIdx = nStartIdx + nCnt;
-    m_Text = m_Text.replaceAt(nStartIdx, nCnt, "");
+    if (nEndIdx <= m_Text.getLength())
+        m_Text = m_Text.replaceAt(nStartIdx, nCnt, "");
 
     // GCAttr(); don't remove all empty ones, just the ones that are in the
     // range but not at the end of the range.
diff --git a/vcl/source/control/tabctrl.cxx b/vcl/source/control/tabctrl.cxx
index 1c42ba9d081a..a7082008eeb3 100644
--- a/vcl/source/control/tabctrl.cxx
+++ b/vcl/source/control/tabctrl.cxx
@@ -256,7 +256,8 @@ Size TabControl::ImplGetItemSize( ImplTabItem* pItem, long nMaxWidth )
         pItem->maFormatText += aAppendStr;
         do
         {
-            pItem->maFormatText = pItem->maFormatText.replaceAt( pItem->maFormatText.getLength()-aAppendStr.getLength()-1, 1, "" );
+            if (pItem->maFormatText.getLength() > aAppendStr.getLength())
+                pItem->maFormatText = pItem->maFormatText.replaceAt( pItem->maFormatText.getLength()-aAppendStr.getLength()-1, 1, "" );
             aSize.setWidth( GetCtrlTextWidth( pItem->maFormatText ) );
             aSize.AdjustWidth(aImageSize.Width() );
             aSize.AdjustWidth(TAB_TABOFFSET_X*2 );
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index 0bee265b0187..636153e8633f 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -2626,11 +2626,17 @@ style::NumberingType::
 
 static OUString lcl_ParseFormat( const OUString& rCommand )
 {
-    //  The command looks like: " DATE \@"dd MMMM yyyy"
+    //  The command looks like: " DATE \@"dd MMMM yyyy" or "09/02/2014"
     //  Remove whitespace permitted by standard between \@ and "
+    OUString command;
     sal_Int32 delimPos = rCommand.indexOf("\\@");
-    sal_Int32 wsChars = rCommand.indexOf('\"') - delimPos - 2;
-    OUString command = rCommand.replaceAt(delimPos+2, wsChars, "");
+    if (delimPos != -1)
+    {
+        sal_Int32 wsChars = rCommand.indexOf('\"') - delimPos - 2;
+        command = rCommand.replaceAt(delimPos+2, wsChars, "");
+    }
+    else
+        command = rCommand;
 
     return msfilter::util::findQuotedText(command, "\\@\"", '\"');
 }


More information about the Libreoffice-commits mailing list