diff options
author | Ryan Harrison <rharrison@chromium.org> | 2017-08-02 16:16:18 -0400 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-08-02 20:37:10 +0000 |
commit | 0811da801dd72e2e0af2d7b9d1e866162df2cee1 (patch) | |
tree | 5f73ca36f6d804571e6b44360f2940a2a1509db5 /core/fxcrt/cfx_bytestring_unittest.cpp | |
parent | b4fee4d5d471475ada1d0d9110e1a534b49477ba (diff) | |
download | pdfium-0811da801dd72e2e0af2d7b9d1e866162df2cee1.tar.xz |
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 <tsepez@chromium.org>
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Diffstat (limited to 'core/fxcrt/cfx_bytestring_unittest.cpp')
-rw-r--r-- | core/fxcrt/cfx_bytestring_unittest.cpp | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/core/fxcrt/cfx_bytestring_unittest.cpp b/core/fxcrt/cfx_bytestring_unittest.cpp index 89c8ac6060..d843afef97 100644 --- a/core/fxcrt/cfx_bytestring_unittest.cpp +++ b/core/fxcrt/cfx_bytestring_unittest.cpp @@ -454,21 +454,25 @@ TEST(fxcrt, ByteStringInsertAtFrontAndInsertAtBack) { TEST(fxcrt, ByteStringDelete) { CFX_ByteString fred("FRED"); - fred.Delete(0, 2); + EXPECT_EQ(4, fred.Delete(0, 0)); + EXPECT_EQ("FRED", fred); + EXPECT_EQ(2, fred.Delete(0, 2)); EXPECT_EQ("ED", fred); - fred.Delete(1); + EXPECT_EQ(1, fred.Delete(1)); + EXPECT_EQ("E", fred); + EXPECT_EQ(1, fred.Delete(-1)); EXPECT_EQ("E", fred); - fred.Delete(-1); + EXPECT_EQ(0, fred.Delete(0)); EXPECT_EQ("", fred); - fred.Delete(1); + EXPECT_EQ(0, fred.Delete(0)); EXPECT_EQ("", fred); CFX_ByteString empty; - empty.Delete(0); + EXPECT_EQ(0, empty.Delete(0)); EXPECT_EQ("", empty); - empty.Delete(-1); + EXPECT_EQ(0, empty.Delete(-1)); EXPECT_EQ("", empty); - empty.Delete(1); + EXPECT_EQ(0, empty.Delete(1)); EXPECT_EQ("", empty); } |