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

Side by Side Diff: base/clipboard_util.cc

Issue 19763: fix off by one in offset values for cf_html. (Closed)
Patch Set: Created 11 years, 10 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 | « no previous file | 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "base/clipboard_util.h" 5 #include "base/clipboard_util.h"
6 6
7 #include <shellapi.h> 7 #include <shellapi.h>
8 #include <shlwapi.h> 8 #include <shlwapi.h>
9 #include <wininet.h> 9 #include <wininet.h>
10 10
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 static const char* start_markup = 422 static const char* start_markup =
423 "<html>\r\n<body>\r\n<!--StartFragment-->\r\n"; 423 "<html>\r\n<body>\r\n<!--StartFragment-->\r\n";
424 static const char* end_markup = 424 static const char* end_markup =
425 "\r\n<!--EndFragment-->\r\n</body>\r\n</html>"; 425 "\r\n<!--EndFragment-->\r\n</body>\r\n</html>";
426 426
427 // Calculate offsets 427 // Calculate offsets
428 size_t start_html_offset = strlen(header) - strlen(NUMBER_FORMAT) * 4 + 428 size_t start_html_offset = strlen(header) - strlen(NUMBER_FORMAT) * 4 +
429 MAX_DIGITS * 4; 429 MAX_DIGITS * 4;
430 if (!base_url.empty()) { 430 if (!base_url.empty()) {
431 start_html_offset += strlen(source_url_prefix) + 431 start_html_offset += strlen(source_url_prefix) +
432 base_url.length() + 1; 432 base_url.length() + 2; // Add 2 for \r\n.
433 } 433 }
434 size_t start_fragment_offset = start_html_offset + strlen(start_markup); 434 size_t start_fragment_offset = start_html_offset + strlen(start_markup);
435 size_t end_fragment_offset = start_fragment_offset + html.length(); 435 size_t end_fragment_offset = start_fragment_offset + html.length();
436 size_t end_html_offset = end_fragment_offset + strlen(end_markup); 436 size_t end_html_offset = end_fragment_offset + strlen(end_markup);
437 437
438 std::string result = StringPrintf(header, start_html_offset, 438 std::string result = StringPrintf(header, start_html_offset,
439 end_html_offset, start_fragment_offset, end_fragment_offset); 439 end_html_offset, start_fragment_offset, end_fragment_offset);
440 if (!base_url.empty()) { 440 if (!base_url.empty()) {
441 result.append(source_url_prefix); 441 result.append(source_url_prefix);
442 result.append(base_url); 442 result.append(base_url);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 size_t tag_start = cf_html.find("StartFragment", markup_start); 476 size_t tag_start = cf_html.find("StartFragment", markup_start);
477 size_t fragment_start = cf_html.find('>', tag_start) + 1; 477 size_t fragment_start = cf_html.find('>', tag_start) + 1;
478 size_t tag_end = cf_html.rfind("EndFragment", std::string::npos); 478 size_t tag_end = cf_html.rfind("EndFragment", std::string::npos);
479 size_t fragment_end = cf_html.rfind('<', tag_end); 479 size_t fragment_end = cf_html.rfind('<', tag_end);
480 if (fragment_start != std::string::npos && 480 if (fragment_start != std::string::npos &&
481 fragment_end != std::string::npos) { 481 fragment_end != std::string::npos) {
482 *html = cf_html.substr(fragment_start, fragment_end - fragment_start); 482 *html = cf_html.substr(fragment_start, fragment_end - fragment_start);
483 TrimWhitespace(*html, TRIM_ALL, html); 483 TrimWhitespace(*html, TRIM_ALL, html);
484 } 484 }
485 } 485 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698