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

Unified Diff: src/d8.cc

Issue 791713003: Allocate memory for external snapshot paths in d8 (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 6 years 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 | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/d8.cc
diff --git a/src/d8.cc b/src/d8.cc
index 653e36694d0c8d9bd94c7e3baaf3c8af3433f08a..132891e2b8a694919c0643118dea5fd8ef82b403 100644
--- a/src/d8.cc
+++ b/src/d8.cc
@@ -1555,11 +1555,13 @@ class StartupDataHandler {
if (natives_blob || snapshot_blob) {
LoadFromFiles(natives_blob, snapshot_blob);
} else {
- char natives[100], snapshot[100];
- LoadFromFiles(
- RelativePath(natives, exec_path, "natives_blob.bin", sizeof(natives)),
- RelativePath(snapshot, exec_path, "snapshot_blob.bin",
- sizeof(snapshot)));
+ char* natives;
+ char* snapshot;
+ LoadFromFiles(RelativePath(&natives, exec_path, "natives_blob.bin"),
+ RelativePath(&snapshot, exec_path, "snapshot_blob.bin"));
+
+ free(natives);
+ free(snapshot);
}
}
@@ -1569,19 +1571,21 @@ class StartupDataHandler {
}
private:
- static char* RelativePath(char* buffer, const char* exec_path,
- const char* name, int buffer_length) {
+ static char* RelativePath(char** buffer, const char* exec_path,
+ const char* name) {
DCHECK(exec_path);
const char* last_slash = strrchr(exec_path, '/');
if (last_slash) {
int after_slash = last_slash - exec_path + 1;
- DCHECK(buffer_length > after_slash);
- strncpy(buffer, exec_path, after_slash);
- buffer[after_slash] = '\0';
- return strncat(buffer, name, buffer_length);
+ int name_length = strlen(name);
+ *buffer =
+ reinterpret_cast<char*>(calloc(after_slash + name_length + 1, 1));
+ strncpy(*buffer, exec_path, after_slash);
+ strncat(*buffer, name, name_length);
} else {
- return strncpy(buffer, name, buffer_length);
+ *buffer = strdup(name);
}
+ return *buffer;
}
void LoadFromFiles(const char* natives_blob, const char* snapshot_blob) {
« 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