[Libreoffice-commits] core.git: 2 commits - include/rtl

Matteo Casalin matteo.casalin at yahoo.com
Tue Jun 23 03:34:08 PDT 2015


 include/rtl/character.hxx |    4 ++--
 include/rtl/strbuf.hxx    |    9 +++++----
 include/rtl/string.hxx    |    9 +++++----
 include/rtl/ustrbuf.hxx   |    9 +++++----
 include/rtl/ustring.hxx   |    9 +++++----
 5 files changed, 22 insertions(+), 18 deletions(-)

New commits:
commit 1b60c3d62deef02788d31c7d60ea1ab12323c150
Author: Matteo Casalin <matteo.casalin at yahoo.com>
Date:   Sun Jun 21 12:47:13 2015 +0200

    Avoid conversion warnings in rtl::get[High|Low]Surrogate
    
    Change-Id: I5eec1f7505e27eedd39081669011f7af42b8a26f
    Signed-off-by: Stephan Bergmann <sbergman at redhat.com>

diff --git a/include/rtl/character.hxx b/include/rtl/character.hxx
index 52151e8..a3d09b9 100644
--- a/include/rtl/character.hxx
+++ b/include/rtl/character.hxx
@@ -261,7 +261,7 @@ inline bool isLowSurrogate(sal_uInt32 code) {
 inline sal_Unicode getHighSurrogate(sal_uInt32 code) {
     assert(code <= 0x10FFFF);
     assert(code >= 0x10000);
-    return ((code - 0x10000) >> 10) | detail::surrogatesHighFirst;
+    return static_cast<sal_Unicode>(((code - 0x10000) >> 10) | detail::surrogatesHighFirst);
 }
 
 /** Get low surrogate half of a non-BMP Unicode code point.
@@ -275,7 +275,7 @@ inline sal_Unicode getHighSurrogate(sal_uInt32 code) {
 inline sal_Unicode getLowSurrogate(sal_uInt32 code) {
     assert(code <= 0x10FFFF);
     assert(code >= 0x10000);
-    return ((code - 0x10000) & 0x3FF) | detail::surrogatesLowFirst;
+    return static_cast<sal_Unicode>(((code - 0x10000) & 0x3FF) | detail::surrogatesLowFirst);
 }
 
 /** Combine surrogates to form a code point.
commit cbe3b2fe0b9d745e22a2bf436ce55141b15f9502
Author: Matteo Casalin <matteo.casalin at yahoo.com>
Date:   Sat Jun 20 15:37:35 2015 +0200

    Avoid conversion warning in O[U]String[Buffer] constructors
    
    Signed-off-by: Stephan Bergmann <sbergman at redhat.com>, modifying the patch to
    carefully keep the undefined behavior in the already existing additions that may
    potentially overflow, instead of making the static_cast<sal_Int32> introduction
    look like end - pData->buffer will be guaranteed to fit into sal_Int32 (which it
    is not).
    
    Change-Id: Id2fb64dc4585dae34257be6968a8905254a3b42d

diff --git a/include/rtl/strbuf.hxx b/include/rtl/strbuf.hxx
index 52d29ca..81773b4 100644
--- a/include/rtl/strbuf.hxx
+++ b/include/rtl/strbuf.hxx
@@ -211,7 +211,7 @@ public:
         pData = rtl_string_alloc( nCapacity );
         char* end = c.addData( pData->buffer );
         *end = '\0';
-        pData->length = end - pData->buffer;
+        pData->length = l;
     }
 #endif
 
@@ -486,13 +486,14 @@ public:
     template< typename T1, typename T2 >
     OStringBuffer& append( const OStringConcat< T1, T2 >& c )
     {
-        const int l = c.length();
+        sal_Int32 l = c.length();
         if( l == 0 )
             return *this;
-        rtl_stringbuffer_ensureCapacity( &pData, &nCapacity, pData->length + l );
+        l += pData->length;
+        rtl_stringbuffer_ensureCapacity( &pData, &nCapacity, l );
         char* end = c.addData( pData->buffer + pData->length );
         *end = '\0';
-        pData->length = end - pData->buffer;
+        pData->length = l;
         return *this;
     }
 #endif
diff --git a/include/rtl/string.hxx b/include/rtl/string.hxx
index 94dad50..56cbf93 100644
--- a/include/rtl/string.hxx
+++ b/include/rtl/string.hxx
@@ -244,7 +244,7 @@ public:
         if (l != 0)
         {
             char* end = c.addData( pData->buffer );
-            pData->length = end - pData->buffer;
+            pData->length = l;
             *end = '\0';
         }
     }
@@ -305,13 +305,14 @@ public:
     template< typename T1, typename T2 >
     OString& operator+=( const OStringConcat< T1, T2 >& c )
     {
-        const int l = c.length();
+        sal_Int32 l = c.length();
         if( l == 0 )
             return *this;
-        rtl_string_ensureCapacity( &pData, pData->length + l );
+        l += pData->length;
+        rtl_string_ensureCapacity( &pData, l );
         char* end = c.addData( pData->buffer + pData->length );
         *end = '\0';
-        pData->length = end - pData->buffer;
+        pData->length = l;
         return *this;
     }
 #endif
diff --git a/include/rtl/ustrbuf.hxx b/include/rtl/ustrbuf.hxx
index abb85a0..04ac8a6 100644
--- a/include/rtl/ustrbuf.hxx
+++ b/include/rtl/ustrbuf.hxx
@@ -181,7 +181,7 @@ public:
         pData = rtl_uString_alloc( nCapacity );
         sal_Unicode* end = c.addData( pData->buffer );
         *end = '\0';
-        pData->length = end - pData->buffer;
+        pData->length = l;
         // TODO realloc in case pData->>length is noticeably smaller than l ?
     }
 #endif
@@ -484,13 +484,14 @@ public:
     template< typename T1, typename T2 >
     OUStringBuffer& append( const OUStringConcat< T1, T2 >& c )
     {
-        const int l = c.length();
+        sal_Int32 l = c.length();
         if( l == 0 )
             return *this;
-        rtl_uStringbuffer_ensureCapacity( &pData, &nCapacity, pData->length + l );
+        l += pData->length;
+        rtl_uStringbuffer_ensureCapacity( &pData, &nCapacity, l );
         sal_Unicode* end = c.addData( pData->buffer + pData->length );
         *end = '\0';
-        pData->length = end - pData->buffer;
+        pData->length = l;
         return *this;
     }
 #endif
diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx
index 2c56443..662e215 100644
--- a/include/rtl/ustring.hxx
+++ b/include/rtl/ustring.hxx
@@ -349,7 +349,7 @@ public:
         if (l != 0)
         {
             sal_Unicode* end = c.addData( pData->buffer );
-            pData->length = end - pData->buffer;
+            pData->length = l;
             *end = '\0';
             // TODO realloc in case pData->length is noticeably smaller than l?
         }
@@ -445,13 +445,14 @@ public:
     template< typename T1, typename T2 >
     OUString& operator+=( const OUStringConcat< T1, T2 >& c )
     {
-        const int l = c.length();
+        sal_Int32 l = c.length();
         if( l == 0 )
             return *this;
-        rtl_uString_ensureCapacity( &pData, pData->length + l );
+        l += pData->length;
+        rtl_uString_ensureCapacity( &pData, l );
         sal_Unicode* end = c.addData( pData->buffer + pData->length );
         *end = '\0';
-        pData->length = end - pData->buffer;
+        pData->length = l;
         return *this;
     }
 #endif


More information about the Libreoffice-commits mailing list