[Libreoffice-commits] core.git: 2 commits - comphelper/source l10ntools/source sal/inc

Stephan Bergmann sbergman at redhat.com
Thu Mar 28 05:31:11 PDT 2013


 comphelper/source/misc/proxyaggregation.cxx |   11 +++++++++--
 l10ntools/source/lngmerge.cxx               |    6 ++++--
 sal/inc/rtl/string.hxx                      |    9 ++++++++-
 sal/inc/rtl/ustring.hxx                     |    9 ++++++++-
 4 files changed, 29 insertions(+), 6 deletions(-)

New commits:
commit acca22d64283905048a9441fd30e7179361f2666
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Thu Mar 28 13:28:03 2013 +0100

    Related rhbz#928568: Detect aggregators listening at themselves
    
    ...which would lead to infinite recursion during disposing.
    
    Change-Id: Ie895dbf8b4497296f2216edeac012f242d720adf

diff --git a/comphelper/source/misc/proxyaggregation.cxx b/comphelper/source/misc/proxyaggregation.cxx
index a8771d6..9a19cf5 100644
--- a/comphelper/source/misc/proxyaggregation.cxx
+++ b/comphelper/source/misc/proxyaggregation.cxx
@@ -17,6 +17,10 @@
  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
  */
 
+#include "sal/config.h"
+
+#include <cassert>
+
 #include <comphelper/proxyaggregation.hxx>
 #include <com/sun/star/reflection/ProxyFactory.hpp>
 
@@ -233,8 +237,11 @@ namespace comphelper
     //--------------------------------------------------------------------
     void SAL_CALL OComponentProxyAggregation::disposing( const EventObject& _rSource ) throw (RuntimeException)
     {
-        // simly disambiguate - this is necessary for MSVC to distinguish
-        // "disposing( EventObject )" from "disposing()"
+        // Simply disambiguate---this is necessary for MSVC to distinguish
+        // "disposing(EventObject)" from "disposing()"; but it is also a good
+        // place to check for recursive calls that would be caused by an object
+        // being registered as an XEventListener at itself (cf. rhbz#928568):
+        assert(_rSource.Source != static_cast< cppu::OWeakObject * >(this));
         OComponentProxyAggregationHelper::disposing( _rSource );
     }
 
commit 7eaf1e93889568b6cd9f721b42a3fd4bbe59f8b6
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Thu Mar 28 13:06:36 2013 +0100

    Half-assed attempt at enforcing operator [] preconditions
    
    ...inspired by comments to <https://gerrit.libreoffice.org/#/c/3068/>
    "String::AppendAscii cleanup in dbaccess," but it quickly becomes apparent that
    lots of code rely on s[s.getLength()] == 0, so live with a weakened precondition
    check for now.
    
    Change-Id: Ifad96c706b14433df4a084ab8054b32433b8b5b6

diff --git a/l10ntools/source/lngmerge.cxx b/l10ntools/source/lngmerge.cxx
index 052f970..364087d 100644
--- a/l10ntools/source/lngmerge.cxx
+++ b/l10ntools/source/lngmerge.cxx
@@ -194,7 +194,8 @@ sal_Bool LngParser::Merge(
     {
         rtl::OString sLine( *(*pLines)[ nPos ] );
         sLine = sLine.trim();
-        if (( sLine[0] == '[' ) &&
+        if (!sLine.isEmpty() &&
+            ( sLine[0] == '[' ) &&
             ( sLine[sLine.getLength() - 1] == ']' ))
         {
             sGroup = getBracketedContent(sLine).trim();
@@ -220,7 +221,8 @@ sal_Bool LngParser::Merge(
         {
             rtl::OString sLine( *(*pLines)[ nPos ] );
             sLine = sLine.trim();
-            if (( sLine[0] == '[' ) &&
+            if (!sLine.isEmpty() &&
+                ( sLine[0] == '[' ) &&
                 ( sLine[sLine.getLength() - 1] == ']' ))
             {
                 sGroup = getBracketedContent(sLine).trim();
diff --git a/sal/inc/rtl/string.hxx b/sal/inc/rtl/string.hxx
index f6cec59..f9eeda2 100644
--- a/sal/inc/rtl/string.hxx
+++ b/sal/inc/rtl/string.hxx
@@ -388,7 +388,14 @@ public:
 
       @since LibreOffice 3.5
     */
-    sal_Char operator [](sal_Int32 index) const { return getStr()[index]; }
+    sal_Char operator [](sal_Int32 index) const {
+        assert(index >= 0 && index <= getLength());
+            //TODO: should really check for < getLength(), but there is quite
+            // some clever code out there that violates this function's
+            // documented precondition and relies on s[s.getLength()] == 0 and
+            // that would need to be fixed first
+        return getStr()[index];
+    }
 
     /**
       Compares two strings.
diff --git a/sal/inc/rtl/ustring.hxx b/sal/inc/rtl/ustring.hxx
index 768f552..0af8b6d 100644
--- a/sal/inc/rtl/ustring.hxx
+++ b/sal/inc/rtl/ustring.hxx
@@ -474,7 +474,14 @@ public:
 
       @since LibreOffice 3.5
     */
-    sal_Unicode operator [](sal_Int32 index) const { return getStr()[index]; }
+    sal_Unicode operator [](sal_Int32 index) const {
+        assert(index >= 0 && index <= getLength());
+            //TODO: should really check for < getLength(), but there is quite
+            // some clever code out there that violates this function's
+            // documented precondition and relies on s[s.getLength()] == 0 and
+            // that would need to be fixed first
+        return getStr()[index];
+    }
 
     /**
       Compares two strings.


More information about the Libreoffice-commits mailing list