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

Unified Diff: base/string_util.cc

Issue 6877008: Add a unittest case of ReplaceStringPlaceholders() (Closed)
Patch Set: Prevent overrun of string parsing Created 9 years, 6 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 | « no previous file | base/string_util_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/string_util.cc
diff --git a/base/string_util.cc b/base/string_util.cc
index 9582f4b9f90238d1152760b5a816abf429e7a4c7..81b9ee7e3995ddaa6b56730008b74ff390f2f2ec 100644
--- a/base/string_util.cc
+++ b/base/string_util.cc
@@ -815,7 +815,6 @@ template<class FormatStringType, class OutStringType>
OutStringType DoReplaceStringPlaceholders(const FormatStringType& format_string,
const std::vector<OutStringType>& subst, std::vector<size_t>* offsets) {
size_t substitutions = subst.size();
- DCHECK(substitutions < 10);
size_t sub_length = 0;
for (typename std::vector<OutStringType>::const_iterator iter = subst.begin();
@@ -840,7 +839,14 @@ OutStringType DoReplaceStringPlaceholders(const FormatStringType& format_string,
}
--i;
} else {
- uintptr_t index = *i - '1';
+ uintptr_t index = 0;
+ while (i != format_string.end() && '0' <= *i && *i <= '9') {
+ index *= 10;
+ index += *i - '0';
+ ++i;
+ }
+ --i;
+ index -= 1;
if (offsets) {
ReplacementOffset r_offset(index,
static_cast<int>(formatted.size()));
« no previous file with comments | « no previous file | base/string_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698