summaryrefslogtreecommitdiff
path: root/fpdfsdk/fpdftext.cpp
diff options
context:
space:
mode:
authorRyan Harrison <rharrison@chromium.org>2017-11-27 19:30:17 +0000
committerChromium commit bot <commit-bot@chromium.org>2017-11-27 19:30:17 +0000
commit3fc7fe5e4d8fa257e35e6ae86fc6cf4d6b5016a2 (patch)
treee7bb4942e6feaf5885d62e8c9de6c6363994beab /fpdfsdk/fpdftext.cpp
parentb388961f8e009e9c3c6c77588057e71caf7eafa9 (diff)
downloadpdfium-3fc7fe5e4d8fa257e35e6ae86fc6cf4d6b5016a2.tar.xz
Change FPDF_GetText to return "" when asked to get 0 characters
BUG=chromium:788103 Change-Id: I8ebdbc78eb14c358d7ac019b96de4828e6071b79 Reviewed-on: https://pdfium-review.googlesource.com/19350 Commit-Queue: Ryan Harrison <rharrison@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'fpdfsdk/fpdftext.cpp')
-rw-r--r--fpdfsdk/fpdftext.cpp21
1 files changed, 9 insertions, 12 deletions
diff --git a/fpdfsdk/fpdftext.cpp b/fpdfsdk/fpdftext.cpp
index ae6841febc..9d7d56311f 100644
--- a/fpdfsdk/fpdftext.cpp
+++ b/fpdfsdk/fpdftext.cpp
@@ -164,29 +164,26 @@ FPDF_EXPORT int FPDF_CALLCONV FPDFText_GetText(FPDF_TEXTPAGE text_page,
int start,
int count,
unsigned short* result) {
- if (start < 0 || count < 1 || !result || !text_page)
+ if (start < 0 || count < 0 || !result || !text_page)
return 0;
CPDF_TextPage* textpage = CPDFTextPageFromFPDFTextPage(text_page);
if (start >= textpage->CountChars())
return 0;
- WideString str = textpage->GetPageText(start, count - 1);
- if (str.GetLength() <= 0)
- return 0;
-
+ WideString str = textpage->GetPageText(start, count);
if (str.GetLength() > static_cast<size_t>(count))
str = str.Left(static_cast<size_t>(count));
// UFT16LE_Encode doesn't handle surrogate pairs properly, so it is expected
// the number of items to stay the same.
- ByteString cbUTF16str = str.UTF16LE_Encode();
- ASSERT(cbUTF16str.GetLength() / kBytesPerCharacter <=
- static_cast<size_t>(count));
- memcpy(result, cbUTF16str.GetBuffer(cbUTF16str.GetLength()),
- cbUTF16str.GetLength());
-
- return cbUTF16str.GetLength() / kBytesPerCharacter;
+ ByteString byte_str = str.UTF16LE_Encode();
+ ASSERT((byte_str.GetLength()) / kBytesPerCharacter <=
+ static_cast<size_t>(count + 1)); // +1 to account for the string
+ // terminator
+ memcpy(result, byte_str.GetBuffer(byte_str.GetLength()),
+ byte_str.GetLength());
+ return (byte_str.GetLength() / kBytesPerCharacter);
}
FPDF_EXPORT int FPDF_CALLCONV FPDFText_CountRects(FPDF_TEXTPAGE text_page,