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

Unified Diff: pdf/pdfium/pdfium_page.cc

Issue 848073003: PDF: Yet another stab at getting WriteInto() buffer sizes correct. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nits 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_engine.cc ('k') | pdf/pdfium/pdfium_range.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pdf/pdfium/pdfium_page.cc
diff --git a/pdf/pdfium/pdfium_page.cc b/pdf/pdfium/pdfium_page.cc
index adf9cac484bfd1334da8f69c38e491fa6760517c..1335f0780cf211ceb08d4c237eab05c6ed2c2d79 100644
--- a/pdf/pdfium/pdfium_page.cc
+++ b/pdf/pdfium/pdfium_page.cc
@@ -11,6 +11,7 @@
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
+#include "pdf/pdfium/pdfium_api_string_buffer_adapter.h"
#include "pdf/pdfium/pdfium_engine.h"
// Used when doing hit detection.
@@ -197,14 +198,10 @@ base::Value* PDFiumPage::GetTextBoxAsValue(double page_height,
} else if (area == WEBLINK_AREA && !link) {
size_t start = 0;
for (size_t i = 0; i < targets.size(); ++i) {
- // Remove the extra NULL character at end.
- // Otherwise, find() will not return any matches.
- if (targets[i].url.size() > 0 &&
- targets[i].url[targets[i].url.size() - 1] == '\0') {
- targets[i].url.resize(targets[i].url.size() - 1);
- }
- // There should only ever be one NULL character
- DCHECK(targets[i].url[targets[i].url.size() - 1] != '\0');
+ // If there is an extra NULL character at end, find() will not return any
+ // matches. There should not be any though.
+ if (!targets[i].url.empty())
+ DCHECK(targets[i].url[targets[i].url.size() - 1] != '\0');
// PDFium may change the case of generated links.
std::string lowerCaseURL = base::StringToLowerASCII(targets[i].url);
@@ -323,9 +320,13 @@ PDFiumPage::Area PDFiumPage::GetLinkTarget(
if (target) {
size_t buffer_size =
FPDFAction_GetURIPath(engine_->doc(), action, NULL, 0);
- if (buffer_size > 1) {
- void* data = WriteInto(&target->url, buffer_size);
- FPDFAction_GetURIPath(engine_->doc(), action, data, buffer_size);
+ if (buffer_size > 0) {
+ PDFiumAPIStringBufferAdapter<std::string> api_string_adapter(
+ &target->url, buffer_size, true);
+ void* data = api_string_adapter.GetData();
+ size_t bytes_written = FPDFAction_GetURIPath(
+ engine_->doc(), action, data, buffer_size);
+ api_string_adapter.Close(bytes_written);
}
}
return WEBLINK_AREA;
@@ -407,9 +408,12 @@ void PDFiumPage::CalculateLinks() {
base::string16 url;
int url_length = FPDFLink_GetURL(links, i, NULL, 0);
if (url_length > 0) {
+ PDFiumAPIStringBufferAdapter<base::string16> api_string_adapter(
+ &url, url_length, true);
unsigned short* data =
- reinterpret_cast<unsigned short*>(WriteInto(&url, url_length + 1));
- FPDFLink_GetURL(links, i, data, url_length);
+ reinterpret_cast<unsigned short*>(api_string_adapter.GetData());
+ int actual_length = FPDFLink_GetURL(links, i, data, url_length);
+ api_string_adapter.Close(actual_length);
}
Link link;
link.url = base::UTF16ToUTF8(url);
« no previous file with comments | « pdf/pdfium/pdfium_engine.cc ('k') | pdf/pdfium/pdfium_range.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698