sal/rtl/strtmpl.hxx | 9 +++++++++ 1 file changed, 9 insertions(+) New commits: commit 713c83c0fc4a0d9950cfa0b598d7c5f4bae15755 Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Sat Mar 5 19:26:38 2022 +0300 Commit: Mike Kaganski <mike.kagan...@collabora.com> CommitDate: Sat Mar 5 18:17:55 2022 +0100
Add checks to avoid finding empty substring / zero character ... which changed in commit 281989007fd7dea997ed9a65f513f80b1aff67dd Author Noel Grandin <n...@peralex.com> Date Tue Jul 01 13:17:01 2014 +0200 Use standard library optimised routines for OUString/OString for optimized cases: strchr/wcschr/strrchr/wcsrchr find trailing zero character, and strstr/wcsstr find empty string; previous/unoptimized code does not find these. This introduced inconsistency between char and sal_Unicode functions on non-Windows, and for sal_Unicode between Windows and non-Windows (because on Windows, optimized code is used for sal_Unicode, while on other platforms, unoptimized code is used). Change-Id: I68529c91b26f4113d9bd7777fc5ac4809349864b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/131064 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> diff --git a/sal/rtl/strtmpl.hxx b/sal/rtl/strtmpl.hxx index 6fa400c0164f..37f274a69cf2 100644 --- a/sal/rtl/strtmpl.hxx +++ b/sal/rtl/strtmpl.hxx @@ -307,6 +307,9 @@ sal_Int32 indexOfChar ( const IMPL_RTL_STRCODE* pStr IMPL_RTL_STRCODE c ) { assert(pStr); + if (!c) + return -1; // Unifies behavior of strchr/wcschr and unoptimized algorithm wrt '\0' + if constexpr (sizeof(IMPL_RTL_STRCODE) == sizeof(char)) { // take advantage of builtin optimisations @@ -361,6 +364,9 @@ sal_Int32 lastIndexOfChar ( const IMPL_RTL_STRCODE* IMPL_RTL_STRCODE c ) { assert(pStr); + if (!c) + return -1; // Unifies behavior of strrchr/wcsrchr and lastIndexOfChar_WithLength wrt '\0' + if constexpr (sizeof(IMPL_RTL_STRCODE) == sizeof(char)) { // take advantage of builtin optimisations @@ -406,6 +412,9 @@ sal_Int32 indexOfStr ( const IMPL_RTL_STRCODE* pStr, { assert(pStr); assert(pSubStr); + /* an empty SubString is always not findable */ + if (*pSubStr == 0) + return -1; if constexpr (sizeof(IMPL_RTL_STRCODE) == sizeof(char)) { // take advantage of builtin optimisations