[Libreoffice-commits] core.git: sal/inc svl/source vcl/source

Stephan Bergmann sbergman at redhat.com
Wed Apr 3 02:28:04 PDT 2013


 sal/inc/rtl/strbuf.hxx         |    6 +++++-
 sal/inc/rtl/ustrbuf.hxx        |    6 +++++-
 svl/source/numbers/zformat.cxx |    4 +++-
 vcl/source/control/field2.cxx  |    2 +-
 4 files changed, 14 insertions(+), 4 deletions(-)

New commits:
commit 8644d10098a10e02c426a4ae80ce179586f35089
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Wed Apr 3 11:27:05 2013 +0200

    Asserting rtl::O[U]StringBuffer::operator [] preconditions
    
    ...and fixing two call-sites.
    
    Change-Id: I8ed8cb189bd5034130b49b2f57156568e6b24716

diff --git a/sal/inc/rtl/strbuf.hxx b/sal/inc/rtl/strbuf.hxx
index 4dabc76..d858c89 100644
--- a/sal/inc/rtl/strbuf.hxx
+++ b/sal/inc/rtl/strbuf.hxx
@@ -417,7 +417,11 @@ public:
 
       @since LibreOffice 3.5
     */
-    sal_Char & operator [](sal_Int32 index) { return pData->buffer[index]; }
+    sal_Char & operator [](sal_Int32 index)
+    {
+        assert(index >= 0 && index < pData->length);
+        return pData->buffer[index];
+    }
 
     /**
         Return a OString instance reflecting the current content
diff --git a/sal/inc/rtl/ustrbuf.hxx b/sal/inc/rtl/ustrbuf.hxx
index 95993fc..abbf3d0 100644
--- a/sal/inc/rtl/ustrbuf.hxx
+++ b/sal/inc/rtl/ustrbuf.hxx
@@ -409,7 +409,11 @@ public:
 
       @since LibreOffice 3.5
     */
-    sal_Unicode & operator [](sal_Int32 index) { return pData->buffer[index]; }
+    sal_Unicode & operator [](sal_Int32 index)
+    {
+        assert(index >= 0 && index < pData->length);
+        return pData->buffer[index];
+    }
 
     /**
         Return a OUString instance reflecting the current content
diff --git a/svl/source/numbers/zformat.cxx b/svl/source/numbers/zformat.cxx
index ee1a27d..73cc37c 100644
--- a/svl/source/numbers/zformat.cxx
+++ b/svl/source/numbers/zformat.cxx
@@ -1522,7 +1522,9 @@ short SvNumberformat::ImpNextSymbol(OUStringBuffer& rString,
                 OUString aUpperDBNum( rChrCls().uppercase( rString.toString(), nPos-1, aDBNum.getLength() ) );
                 sal_Unicode cUpper = aUpperNatNum[0];
                 sal_Int32 nNatNumNum = rString.toString().copy( nPos - 1 + aNatNum.getLength() ).toInt32();
-                sal_Unicode cDBNum = rString[ nPos - 1 + aDBNum.getLength()];
+                sal_Unicode cDBNum =
+                    nPos - 1 + aDBNum.getLength() < rString.getLength()
+                    ? rString[nPos - 1 + aDBNum.getLength()] : 0;
                 if ( aUpperNatNum == aNatNum && 0 <= nNatNumNum && nNatNumNum <= 19 )
                 {
                     sBuffSymbol.stripStart((sal_Unicode)'[');
diff --git a/vcl/source/control/field2.cxx b/vcl/source/control/field2.cxx
index b988cb8..8b9972d 100644
--- a/vcl/source/control/field2.cxx
+++ b/vcl/source/control/field2.cxx
@@ -2265,7 +2265,7 @@ static sal_Bool ImplTimeGetValue( const OUString& rStr, Time& rTime,
             return sal_False;
 
         nSepPos = aStr.indexOf( rLocaleDataWrapper.getTimeSep() );
-        if ( aStr[0] == '-' )
+        if ( !aStr.isEmpty() && aStr[0] == '-' )
             bNegative = sal_True;
         if ( nSepPos >= 0 )
         {


More information about the Libreoffice-commits mailing list