chart2/source/controller/main/DrawCommandDispatch.cxx | 2 +- sal/qa/rtl/oustring/rtl_OUString2.cxx | 9 --------- sal/qa/rtl/oustring/rtl_ustr.cxx | 10 +++++++--- sal/rtl/strtmpl.hxx | 1 + 4 files changed, 9 insertions(+), 13 deletions(-)
New commits: commit dcd5fa0a7b896fd585ef964cf62ae70d247250f1 Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Wed Mar 9 11:25:54 2022 +0300 Commit: Mike Kaganski <mike.kagan...@collabora.com> CommitDate: Wed Mar 9 14:04:03 2022 +0100 Drop misguided test added in 82a1d32d3d3ac1b4b0a6d4cfaca791c77d9b3c03 The documented precondition is that index must not be greater than the length of string. Just assert that, and fix the found misuse. The added test is for in-place replacement, just in case. Change-Id: I3c545a6f0bf913fe93e2bef83ce733359c193065 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/131232 Reviewed-by: Stephan Bergmann <sberg...@redhat.com> Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> Tested-by: Jenkins diff --git a/chart2/source/controller/main/DrawCommandDispatch.cxx b/chart2/source/controller/main/DrawCommandDispatch.cxx index a20d2ba1a7fb..afc3b907828d 100644 --- a/chart2/source/controller/main/DrawCommandDispatch.cxx +++ b/chart2/source/controller/main/DrawCommandDispatch.cxx @@ -533,7 +533,7 @@ bool DrawCommandDispatch::parseCommandURL( const OUString& rCommandURL, sal_uInt OUString aBaseCommand; OUString aType; - sal_Int32 nIndex = 1; + sal_Int32 nIndex = std::min(sal_Int32(1), rCommandURL.getLength()); OUString aToken = rCommandURL.getToken( 0, '.', nIndex ); if ( nIndex == -1 || aToken.isEmpty() ) { diff --git a/sal/qa/rtl/oustring/rtl_OUString2.cxx b/sal/qa/rtl/oustring/rtl_OUString2.cxx index 5f68629a4c09..22e731fd16f1 100644 --- a/sal/qa/rtl/oustring/rtl_OUString2.cxx +++ b/sal/qa/rtl/oustring/rtl_OUString2.cxx @@ -794,14 +794,6 @@ public: // should not GPF with negative index } - void getToken_007() - { - OUString suTokenStr("a;b"); - sal_Int32 n = 5; // greater than string length - CPPUNIT_ASSERT_EQUAL(OUString(), suTokenStr.getToken(0, ';', n)); - CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), n); - } - CPPUNIT_TEST_SUITE(getToken); CPPUNIT_TEST(getToken_000); CPPUNIT_TEST(getToken_001); @@ -810,7 +802,6 @@ public: CPPUNIT_TEST(getToken_004); CPPUNIT_TEST(getToken_005); CPPUNIT_TEST(getToken_006); - CPPUNIT_TEST(getToken_007); CPPUNIT_TEST_SUITE_END(); }; // class getToken diff --git a/sal/qa/rtl/oustring/rtl_ustr.cxx b/sal/qa/rtl/oustring/rtl_ustr.cxx index 873d771f9457..f5c405dfd948 100644 --- a/sal/qa/rtl/oustring/rtl_ustr.cxx +++ b/sal/qa/rtl/oustring/rtl_ustr.cxx @@ -1031,9 +1031,13 @@ namespace rtl_ustr class getToken : public CppUnit::TestFixture { void getToken_000() - { - // TODO - } + { + OUString s("a;b;c"); + // Replace the string in place + const sal_Int32 i = rtl_uString_getToken(&s.pData, s.pData, 1, ';', 0); + CPPUNIT_ASSERT_EQUAL(sal_Int32(4), i); + CPPUNIT_ASSERT_EQUAL(OUString("b"), s); + } CPPUNIT_TEST_SUITE(getToken); CPPUNIT_TEST(getToken_000); diff --git a/sal/rtl/strtmpl.hxx b/sal/rtl/strtmpl.hxx index 0f0cc6755eb3..07ea6d6cbba8 100644 --- a/sal/rtl/strtmpl.hxx +++ b/sal/rtl/strtmpl.hxx @@ -1256,6 +1256,7 @@ sal_Int32 getToken ( IMPL_RTL_STRINGDATA** ppThis { assert(ppThis); assert(pStr); + assert(nIndex <= pStr->length); // Set ppThis to an empty string and return -1 if either nToken or nIndex is // negative: