summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2020-11-20 18:26:43 +0100
committerStephan Bergmann <sbergman@redhat.com>2020-11-21 13:32:21 +0100
commit142e8ccd3aa14a347f44bd09fa1020b097298140 (patch)
tree6fd02f6b694460539020844991ad248bacd1b0d8 /include
parent01baeab99890e5650b3dabc15f8d900490a5a133 (diff)
Relax non-null requirement for some rtl_uString_* functions
...that take a pointer and a length, and where it should be OK that the pointer is null if the length is zero. Those rtl_uString_* functions are targets of OUString member functions that take std::[u16]string_view arguments, and 19926ed35ebb623fc896942b1f232b83edf1fc1e "loplugin:stringview: Flag empty string converted to string view" (which changed some call sites to pass in default- constructed std::[u16]string_view, for which data() returns null) revealed that those rtl_uString_* functions were not prepared for such input. (The guardings of memcpy are necessary because memcpy still requires its pointer arguments to be non-null, even if the corresponding length is zero.) The new sal/qa/rtl/strings/test_strings_defaultstringview.cxx systematically tests all O[U]String[Buffer] member functions taking std::[u16]string_view arguments. It revealed one further issue in IMPL_RTL_STRNAME(compare_WithLength), where UBSan reported a nullptr-with-nonzero-offset > sal/rtl/strtmpl.cxx:149:9: runtime error: applying non-zero offset 18446744073709551614 to null pointer Also, rtl_uString_newReplaceFirstUtf16LUtf16L was found to lack a check for its `from` argument to be non-null. Change-Id: I6a7a712570f7d1e8d52097208c8a43a5a24797af Reviewed-on: https://gerrit.libreoffice.org/c/core/+/106295 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'include')
-rw-r--r--include/rtl/ustring.h16
1 files changed, 8 insertions, 8 deletions
diff --git a/include/rtl/ustring.h b/include/rtl/ustring.h
index abd33bb77f15..9e61df974618 100644
--- a/include/rtl/ustring.h
+++ b/include/rtl/ustring.h
@@ -1495,8 +1495,8 @@ SAL_DLLPUBLIC void SAL_CALL rtl_uString_newConcatAsciiL(
@param left a valid string.
- @param right must not be null and must point to memory of at least
- \p rightLength UTF-16 code units
+ @param right must point to memory of at least \p rightLength UTF-16 code units; may be null if
+ \p rigthLength is zero
@param rightLength the length of the \p right string; must be non-negative
@@ -1763,13 +1763,13 @@ SAL_DLLPUBLIC void SAL_CALL rtl_uString_newReplaceFirstUtf16LAsciiL(
@param str pointer to the original string; must not be null
- @param from pointer to the substring to be replaced; must not be null and
- must point to memory of at least \p fromLength UTF-16 code units
+ @param from pointer to the substring to be replaced; must point to memory of at least
+ \p fromLength UTF-16 code units; may be null if \p toLength is zero
@param fromLength the length of the \p from substring; must be non-negative
- @param to pointer to the substring to be replaced; must not be null and
- must point to memory of at least \p toLength UTF-16 code units
+ @param to pointer to the substring to be replaced; must point to memory of at least \p toLength
+ UTF-16 code units; may be null if \p toLength is zero
@param toLength the length of the \p to substring; must be non-negative
@@ -1927,8 +1927,8 @@ SAL_DLLPUBLIC void SAL_CALL rtl_uString_newReplaceAllAsciiLAsciiL(
@param fromLength the length of the \p from substring; must be non-negative
- @param to pointer to the substring to be replaced; must not be null and
- must point to memory of at least \p toLength UTF-16 code units
+ @param to pointer to the substring to be replaced; must point to memory of at least \p toLength
+ UTF-16 code units; may be null if \p toLength is zero
@param toLength the length of the \p to substring; must be non-negative