From a09168be68e09c8374829895ac335d4df7c65991 Mon Sep 17 00:00:00 2001 From: jochen Date: Thu, 18 Dec 2014 03:01:42 -0800 Subject: [PATCH] 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} --- src/natives-external.cc | 17 ++++++++--------- src/utils.h | 2 +- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/natives-external.cc b/src/natives-external.cc index 138abe1e5..e601808fe 100644 --- a/src/natives-external.cc +++ b/src/natives-external.cc @@ -82,15 +82,14 @@ class NativesStore { NativesStore() : debugger_count_(0) {} Vector NameFromId(const byte* id, int id_length) { - Vector name(Vector::New(id_length + 11)); - SimpleStringBuilder builder(name.start(), name.length()); - builder.AddString("native "); - builder.AddSubstring(reinterpret_cast(id), id_length); - builder.AddString(".js"); - builder.Finalize(); - // SimpleStringBuilder wants zero-byte; the caller does not. - DCHECK(name[name.length() - 1] == '\0'); - name.Truncate(name.length() - 1); + const char native[] = "native "; + const char extension[] = ".js"; + Vector name(Vector::New(id_length + sizeof(native) - 1 + + sizeof(extension) - 1)); + memcpy(name.start(), native, sizeof(native) - 1); + memcpy(name.start() + sizeof(native) - 1, id, id_length); + memcpy(name.start() + sizeof(native) - 1 + id_length, extension, + sizeof(extension) - 1); return Vector::cast(name); } diff --git a/src/utils.h b/src/utils.h index d5685c982..525c6f87d 100644 --- a/src/utils.h +++ b/src/utils.h @@ -863,7 +863,7 @@ class SimpleStringBuilder { // compute the length of the input string. 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. void AddSubstring(const char* s, int n); -- 2.34.1