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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « pdf/pdfium/pdfium_page.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "pdf/pdfium/pdfium_range.h" 5 #include "pdf/pdfium/pdfium_range.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 9
10 namespace chrome_pdf { 10 namespace chrome_pdf {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 cached_screen_rects_.push_back( 52 cached_screen_rects_.push_back(
53 page_->PageToScreen(offset, zoom, left, top, right, bottom, rotation)); 53 page_->PageToScreen(offset, zoom, left, top, right, bottom, rotation));
54 } 54 }
55 55
56 return cached_screen_rects_; 56 return cached_screen_rects_;
57 } 57 }
58 58
59 base::string16 PDFiumRange::GetText() { 59 base::string16 PDFiumRange::GetText() {
60 int index = char_index_; 60 int index = char_index_;
61 int count = char_count_; 61 int count = char_count_;
62 if (!count) 62 base::string16 rv;
63 return base::string16();
64 if (count < 0) { 63 if (count < 0) {
65 count *= -1; 64 count *= -1;
66 index -= count - 1; 65 index -= count - 1;
67 } 66 }
68 67
69 base::string16 rv; 68 if (count > 0) {
70 unsigned short* data = 69 unsigned short* data =
71 reinterpret_cast<unsigned short*>(WriteInto(&rv, count + 1)); 70 reinterpret_cast<unsigned short*>(WriteInto(&rv, count + 1));
72 if (data) { 71 // |written| includes the trailing terminator, so get rid of the trailing
72 // 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
73 int written = FPDFText_GetText(page_->GetTextPage(), index, count, data); 73 int written = FPDFText_GetText(page_->GetTextPage(), index, count, data);
74 rv.reserve(written); 74 if (written < 1)
75 rv.resize(0);
76 else
77 rv.resize(written - 1);
75 } 78 }
79
76 return rv; 80 return rv;
77 } 81 }
78 82
79 } // namespace chrome_pdf 83 } // namespace chrome_pdf
OLDNEW
« 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