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

Unified Diff: src/heap.cc

Issue 6524031: Terminate on \0 in data passed to String::New() (Closed)
Patch Set: Created 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | test/cctest/test-strings.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/heap.cc
diff --git a/src/heap.cc b/src/heap.cc
index f88ebda53d117dfd5b283b513f7743824f1d408c..8a92c5b07633ab3ea16421ed4ad6065ac262b9cc 100644
--- a/src/heap.cc
+++ b/src/heap.cc
@@ -3348,9 +3348,12 @@ MaybeObject* Heap::AllocateStringFromAscii(Vector<const char> string,
// Copy the characters into the new object.
SeqAsciiString* string_result = SeqAsciiString::cast(result);
- for (int i = 0; i < string.length(); i++) {
+ int i;
+ for (i = 0; i < string.length(); i++) {
string_result->SeqAsciiStringSet(i, string[i]);
+ if (string[i] == '\0') break;
}
+ string_result->set_length(i);
return result;
}
@@ -3378,11 +3381,14 @@ MaybeObject* Heap::AllocateStringFromUtf8Slow(Vector<const char> string,
// Convert and copy the characters into the new object.
String* string_result = String::cast(result);
decoder->Reset(string.start(), string.length());
- for (int i = 0; i < chars; i++) {
+ int i;
+ for (i = 0; i < chars; i++) {
uc32 r = decoder->GetNext();
if (r > kMaxSupportedChar) { r = unibrow::Utf8::kBadChar; }
string_result->Set(i, r);
+ if (r == 0) break;
}
+ string_result->set_length(i);
return result;
}
« no previous file with comments | « no previous file | test/cctest/test-strings.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698