From b9c806b9e3631d76b8ceaa6208497aba60c75f83 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Thu, 14 Apr 2022 18:52:19 +0200 Subject: [PATCH] address potential find/rfind failures in the conversion in commit 74957c7d2f3697fbf2b6f4d6a31c61d5d7df039b Author: Noel Grandin Date: Wed Apr 13 13:54:22 2022 +0200 use more string_view in l10ntools where the prior code might have been relying on the -1 returned by indexOf and lastIndexOd Change-Id: Ief5dedccbaf4e14e5f59aa3c2f7481ff0bb7e2e8 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133027 Tested-by: Jenkins Reviewed-by: Stephan Bergmann --- l10ntools/source/merge.cxx | 13 +++++++++---- l10ntools/source/po.cxx | 5 ++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/l10ntools/source/merge.cxx b/l10ntools/source/merge.cxx index 8a6964c61fa4..588cb73d8614 100644 --- a/l10ntools/source/merge.cxx +++ b/l10ntools/source/merge.cxx @@ -34,10 +34,15 @@ namespace { OString lcl_NormalizeFilename(std::string_view rFilename) { - return OString(rFilename.substr( - std::max( - rFilename.rfind( '\\' ), - rFilename.rfind( '/' ))+1)); + size_t idx1 = rFilename.rfind( '\\' ); + size_t idx2 = rFilename.rfind( '/' ); + if (idx1 == std::string_view::npos && idx2 == std::string_view::npos) + return OString(rFilename); + if (idx1 == std::string_view::npos) + idx1 = 0; + if (idx2 == std::string_view::npos) + idx2 = 0; + return OString(rFilename.substr(std::max(idx1, idx2)+1)); }; bool lcl_ReadPoChecked( diff --git a/l10ntools/source/po.cxx b/l10ntools/source/po.cxx index b93126838c99..62d09e1e7407 100644 --- a/l10ntools/source/po.cxx +++ b/l10ntools/source/po.cxx @@ -257,7 +257,10 @@ PoEntry::PoEntry( throw WRONGHELPTEXT; m_pGenPo.reset( new GenPoEntry() ); - OString sReference(rSourceFile.substr(rSourceFile.rfind('/')+1)); + size_t idx = rSourceFile.rfind('/'); + if (idx == std::string_view::npos) + idx = 0; + OString sReference(rSourceFile.substr(idx+1)); m_pGenPo->setReference(sReference); OString sMsgCtxt =