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; |
} |