summaryrefslogtreecommitdiff
path: root/sal
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2022-03-09 11:25:54 +0300
committerMike Kaganski <mike.kaganski@collabora.com>2022-03-09 14:04:03 +0100
commitdcd5fa0a7b896fd585ef964cf62ae70d247250f1 (patch)
treeef51bf00d1fe6b09dd21f701a3c423d7e4ec4560 /sal
parentdd4dbc70d413ada95632eb818b4d435a14e87303 (diff)
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 <sbergman@redhat.com> Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com> Tested-by: Jenkins
Diffstat (limited to 'sal')
-rw-r--r--sal/qa/rtl/oustring/rtl_OUString2.cxx9
-rw-r--r--sal/qa/rtl/oustring/rtl_ustr.cxx10
-rw-r--r--sal/rtl/strtmpl.hxx1
3 files changed, 8 insertions, 12 deletions
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: