From 0811da801dd72e2e0af2d7b9d1e866162df2cee1 Mon Sep 17 00:00:00 2001 From: Ryan Harrison Date: Wed, 2 Aug 2017 16:16:18 -0400 Subject: Remove support for out of bounds params in Delete The existing implementation of Delete on the string classes handles some cases where the range being deleted is out of bounds by clipping it to the valid range. This behaviour can lead to programming problems in the calling code being masked by the fact the Delete method still does something. The new version of these methods does an early return if the parameters are invalid. This change also effectively removes support for negative string sizes from the Delete method, so converting FX_STRSIZE to be unsigned will be easier. BUG=pdfium:828 Change-Id: Idbb4a62f70a75eba06e7809e011b25da2d7404c4 Reviewed-on: https://pdfium-review.googlesource.com/9890 Reviewed-by: Tom Sepez Commit-Queue: Ryan Harrison --- core/fxcrt/cfx_widestring_unittest.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'core/fxcrt/cfx_widestring_unittest.cpp') diff --git a/core/fxcrt/cfx_widestring_unittest.cpp b/core/fxcrt/cfx_widestring_unittest.cpp index a763f8abbd..6e7b63c5fa 100644 --- a/core/fxcrt/cfx_widestring_unittest.cpp +++ b/core/fxcrt/cfx_widestring_unittest.cpp @@ -414,21 +414,25 @@ TEST(fxcrt, WideStringInsertAtFrontAndInsertAtBack) { TEST(fxcrt, WideStringDelete) { CFX_WideString fred(L"FRED"); - fred.Delete(0, 2); + EXPECT_EQ(4, fred.Delete(0, 0)); + EXPECT_EQ(L"FRED", fred); + EXPECT_EQ(2, fred.Delete(0, 2)); EXPECT_EQ(L"ED", fred); - fred.Delete(1); + EXPECT_EQ(1, fred.Delete(1)); + EXPECT_EQ(L"E", fred); + EXPECT_EQ(1, fred.Delete(-1)); EXPECT_EQ(L"E", fred); - fred.Delete(-1); + EXPECT_EQ(0, fred.Delete(0)); EXPECT_EQ(L"", fred); - fred.Delete(1); + EXPECT_EQ(0, fred.Delete(0)); EXPECT_EQ(L"", fred); CFX_WideString empty; - empty.Delete(0); + EXPECT_EQ(0, empty.Delete(0)); EXPECT_EQ(L"", empty); - empty.Delete(-1); + EXPECT_EQ(0, empty.Delete(-1)); EXPECT_EQ(L"", empty); - empty.Delete(1); + EXPECT_EQ(0, empty.Delete(1)); EXPECT_EQ(L"", empty); } -- cgit v1.2.3