[Libreoffice-commits] core.git: Branch 'libreoffice-5-1' - sal/rtl

Michael Stahl mstahl at redhat.com
Thu Sep 29 20:35:46 UTC 2016


 sal/rtl/strtmpl.cxx |    9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

New commits:
commit 7bc09f32ce86c6ed0df00ad72451b41204e0162f
Author: Michael Stahl <mstahl at redhat.com>
Date:   Thu Sep 29 13:26:19 2016 +0200

    tdf#83306: sal: fix compare of rtl::OUString/OString containing '\0'
    
    For whatever reason oox shape import code uses OUStrings that contain
    '\0' characters.
    
    The rtl_uString / rtl_String are allowed to contain '\0' but the
    strncmp/wcsncmp functions stop comparing on the first '\0', so use
    memcmp/wmemcmp instead.
    
    (regression from 281989007fd7dea997ed9a65f513f80b1aff67dd)
    
    Change-Id: If148927f19d065a21f32f3c14433b0bda7ae9301
    Reviewed-on: https://gerrit.libreoffice.org/29384
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Michael Stahl <mstahl at redhat.com>
    (cherry picked from commit de7ed418e7813c85f192b558ff06e976eccaa54d)
    Reviewed-on: https://gerrit.libreoffice.org/29388
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/sal/rtl/strtmpl.cxx b/sal/rtl/strtmpl.cxx
index 41ab63f..8370c94 100644
--- a/sal/rtl/strtmpl.cxx
+++ b/sal/rtl/strtmpl.cxx
@@ -127,14 +127,15 @@ sal_Int32 SAL_CALL IMPL_RTL_STRNAME( compare_WithLength )( const IMPL_RTL_STRCOD
 #if !IMPL_RTL_IS_USTRING
     // take advantage of builtin optimisations
     sal_Int32 nMin = std::min(nStr1Len, nStr2Len);
-    sal_Int32 nRet = strncmp(pStr1, pStr2, nMin);
+    sal_Int32 nRet = memcmp(pStr1, pStr2, nMin);
     return nRet == 0 ? nStr1Len - nStr2Len : nRet;
 #else
     if (sizeof(IMPL_RTL_STRCODE) == sizeof(wchar_t))
     {
         // take advantage of builtin optimisations
         sal_Int32 nMin = std::min(nStr1Len, nStr2Len);
-        sal_Int32 nRet = wcsncmp(reinterpret_cast<wchar_t const *>(pStr1), reinterpret_cast<wchar_t const *>(pStr2), nMin);
+        sal_Int32 nRet = wmemcmp(reinterpret_cast<wchar_t const *>(pStr1),
+                reinterpret_cast<wchar_t const *>(pStr2), nMin);
         return nRet == 0 ? nStr1Len - nStr2Len : nRet;
     }
     else
@@ -170,7 +171,7 @@ sal_Int32 SAL_CALL IMPL_RTL_STRNAME( shortenedCompare_WithLength )( const IMPL_R
 #if !IMPL_RTL_IS_USTRING
     // take advantage of builtin optimisations
     sal_Int32 nMin = std::min(std::min(nStr1Len, nStr2Len), nShortenedLength);
-    sal_Int32 nRet = strncmp(pStr1, pStr2, nMin);
+    sal_Int32 nRet = memcmp(pStr1, pStr2, nMin);
     if (nRet == 0 && nShortenedLength > std::min(nStr1Len, nStr2Len))
         return nStr1Len - nStr2Len;
     return nRet;
@@ -179,7 +180,7 @@ sal_Int32 SAL_CALL IMPL_RTL_STRNAME( shortenedCompare_WithLength )( const IMPL_R
     {
         // take advantage of builtin optimisations
         sal_Int32 nMin = std::min(std::min(nStr1Len, nStr2Len), nShortenedLength);
-        sal_Int32 nRet = wcsncmp(reinterpret_cast<wchar_t const *>(pStr1), reinterpret_cast<wchar_t const *>(pStr2), nMin);
+        sal_Int32 nRet = wmemcmp(reinterpret_cast<wchar_t const *>(pStr1), reinterpret_cast<wchar_t const *>(pStr2), nMin);
         if (nRet == 0 && nShortenedLength > std::min(nStr1Len, nStr2Len))
             return nStr1Len - nStr2Len;
         return nRet;


More information about the Libreoffice-commits mailing list