Commit a09168be authored by jochen's avatar jochen Committed by Commit bot

Don't use AddSubstring for external natives

The input string is not necessarily zero terminated

BUG=chromium:443230
R=adamk@chromium.org
LOG=n

Review URL: https://codereview.chromium.org/795383003

Cr-Commit-Position: refs/heads/master@{#25879}
parent 7edd6efd
...@@ -82,15 +82,14 @@ class NativesStore { ...@@ -82,15 +82,14 @@ class NativesStore {
NativesStore() : debugger_count_(0) {} NativesStore() : debugger_count_(0) {}
Vector<const char> NameFromId(const byte* id, int id_length) { Vector<const char> NameFromId(const byte* id, int id_length) {
Vector<char> name(Vector<char>::New(id_length + 11)); const char native[] = "native ";
SimpleStringBuilder builder(name.start(), name.length()); const char extension[] = ".js";
builder.AddString("native "); Vector<char> name(Vector<char>::New(id_length + sizeof(native) - 1 +
builder.AddSubstring(reinterpret_cast<const char*>(id), id_length); sizeof(extension) - 1));
builder.AddString(".js"); memcpy(name.start(), native, sizeof(native) - 1);
builder.Finalize(); memcpy(name.start() + sizeof(native) - 1, id, id_length);
// SimpleStringBuilder wants zero-byte; the caller does not. memcpy(name.start() + sizeof(native) - 1 + id_length, extension,
DCHECK(name[name.length() - 1] == '\0'); sizeof(extension) - 1);
name.Truncate(name.length() - 1);
return Vector<const char>::cast(name); return Vector<const char>::cast(name);
} }
......
...@@ -863,7 +863,7 @@ class SimpleStringBuilder { ...@@ -863,7 +863,7 @@ class SimpleStringBuilder {
// compute the length of the input string. // compute the length of the input string.
void AddString(const char* s); void AddString(const char* s);
// Add the first 'n' characters of the given string 's' to the // Add the first 'n' characters of the given 0-terminated string 's' to the
// builder. The input string must have enough characters. // builder. The input string must have enough characters.
void AddSubstring(const char* s, int n); void AddSubstring(const char* s, int n);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment