Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(821)

Unified Diff: pdf/pdfium/pdfium_range.cc

Issue 833263003: PDF: Fix extra NUL characters from incorrect WriteInto() calls. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pdf/pdfium/pdfium_page.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pdf/pdfium/pdfium_range.cc
diff --git a/pdf/pdfium/pdfium_range.cc b/pdf/pdfium/pdfium_range.cc
index c77d5906dd28b7e831bd746246d02e37abc5caf0..226d51284136ebb35fe0cd3b93c015da702224b9 100644
--- a/pdf/pdfium/pdfium_range.cc
+++ b/pdf/pdfium/pdfium_range.cc
@@ -59,20 +59,24 @@ std::vector<pp::Rect> PDFiumRange::GetScreenRects(const pp::Point& offset,
base::string16 PDFiumRange::GetText() {
int index = char_index_;
int count = char_count_;
- if (!count)
- return base::string16();
+ base::string16 rv;
if (count < 0) {
count *= -1;
index -= count - 1;
}
- base::string16 rv;
- unsigned short* data =
- reinterpret_cast<unsigned short*>(WriteInto(&rv, count + 1));
- if (data) {
+ if (count > 0) {
+ unsigned short* data =
+ reinterpret_cast<unsigned short*>(WriteInto(&rv, count + 1));
+ // |written| includes the trailing terminator, so get rid of the trailing
+ // NUL character by calling resize().
raymes 2015/01/06 05:43:24 Not sure if you want to put this comment above you
Lei Zhang 2015/01/06 22:53:03 Comment added. Some places call len = Foo(NULL_buf
int written = FPDFText_GetText(page_->GetTextPage(), index, count, data);
- rv.reserve(written);
+ if (written < 1)
+ rv.resize(0);
+ else
+ rv.resize(written - 1);
}
+
return rv;
}
« no previous file with comments | « pdf/pdfium/pdfium_page.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698