[Libreoffice-commits] core.git: sal/rtl

Stephan Bergmann (via logerrit) logerrit at kemper.freedesktop.org
Tue Dec 8 16:44:16 UTC 2020


 sal/rtl/strtmpl.cxx |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

New commits:
commit 1efec9ec21dba32335e311d367b636538e219621
Author:     Stephan Bergmann <sbergman at redhat.com>
AuthorDate: Tue Dec 8 16:25:13 2020 +0100
Commit:     Stephan Bergmann <sbergman at redhat.com>
CommitDate: Tue Dec 8 17:43:30 2020 +0100

    Tighten rtl_{string,uString}_newFromStr_WithLength implementation
    
    While the documented interface was already narrow (or at least didn't suggest
    that the length argument could reasonably be negative), the implementation was
    somewhat broader:  For one, it allowed the character pointer to be null even
    when the length was non-zero, which looks more like a call-site bug than like a
    useful feature.  And for another, while it did assert that the length is non-
    negative, it nevertheless then checked "overly defensively" for <= 0 rather than
    == 0 down the road.
    
    Change-Id: I084148aaa4b9c4aea16729b0ce90b73ccbe73ebe
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107425
    Tested-by: Jenkins
    Reviewed-by: Stephan Bergmann <sbergman at redhat.com>

diff --git a/sal/rtl/strtmpl.cxx b/sal/rtl/strtmpl.cxx
index 082dcd7d3913..bf58db0ba037 100644
--- a/sal/rtl/strtmpl.cxx
+++ b/sal/rtl/strtmpl.cxx
@@ -1356,10 +1356,11 @@ void SAL_CALL IMPL_RTL_STRINGNAME( newFromStr_WithLength )( IMPL_RTL_STRINGDATA*
     SAL_THROW_EXTERN_C()
 {
     assert(ppThis);
+    assert(pCharStr != nullptr || nLen == 0);
     assert(nLen >= 0);
     IMPL_RTL_STRINGDATA* pOrg;
 
-    if ( !pCharStr || (nLen <= 0) )
+    if ( nLen == 0 )
     {
         IMPL_RTL_STRINGNAME( new )( ppThis );
         return;


More information about the Libreoffice-commits mailing list