Fix a misuse of two-argument std string_view rfind

...introduced in 655b6c2f46
"loplugin:stringviewparam".  Unlike its O[U]String lastIndexOf(x, n)
counterpart (which looks for the last x whose end position, exclusive, is <= n),
string_view rfind(x, n) looks for the last x whose start position, inclusive, is
<= n.  (So here would have left slash unchanged.)  (And the seemingly simpler

  jvm_dll.rfind('\\', slash - 1)

would fail when slash is zero, as in that case it would call rfind with a second
argument of npos, i.e., search for the last '\\' in the complete jvm_dll.)

Change-Id: I148a5db860d4b9e9d58a4a8847880a7a7020c5a5
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/140486
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
This commit is contained in:
Stephan Bergmann
2022-09-23 15:52:21 +02:00
parent e14a6b3f37
commit 93e234c45c
@@ -486,7 +486,7 @@ static void load_msvcr(std::u16string_view jvm_dll, std::u16string_view msvcr)
// Then check if msvcr71.dll is in the parent folder of where
// jvm.dll is. That is currently (1.6.0_22) as far as I know the
// normal case.
slash = jvm_dll.rfind('\\', slash);
slash = jvm_dll.substr(0, slash).rfind('\\');
if (slash == std::u16string_view::npos)
return;