summaryrefslogtreecommitdiff
path: root/sal
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2020-12-08 16:25:13 +0100
committerStephan Bergmann <sbergman@redhat.com>2020-12-08 17:43:30 +0100
commit1efec9ec21dba32335e311d367b636538e219621 (patch)
tree9397d4b44c9b1a53602ddca5bac17aac94caed81 /sal
parent390866bc35eb9c0cce156fcd22079847f3117255 (diff)
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@redhat.com>
Diffstat (limited to 'sal')
-rw-r--r--sal/rtl/strtmpl.cxx3
1 files changed, 2 insertions, 1 deletions
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;