From 348c7871b6c93d8870a04f7002885674df5ab9d6 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Tue, 4 Feb 2020 15:52:39 +0100 Subject: [PATCH] src: remove fixed-size GetHumanReadableProcessName Remove the version of GetHumanReadableProcessName() that operates on a fixed-size buffer. The only remaining caller is Assert() which might get called in contexts where dynamically allocating memory isn't possible but as Assert() calls printf(), which also allocates memory when necessary, this commit is unlikely to make matters much worse. PR-URL: https://github.com/nodejs/node/pull/31633 Fixes: https://github.com/nodejs/node/issues/31631 Reviewed-By: James M Snell Reviewed-By: Anna Henningsen Reviewed-By: Colin Ihrig Reviewed-By: Gus Caplan Reviewed-By: David Carlier Reviewed-By: Rich Trott --- src/node_errors.cc | 5 ++--- src/node_internals.h | 1 - src/util.cc | 7 ------- 3 files changed, 2 insertions(+), 11 deletions(-) diff --git a/src/node_errors.cc b/src/node_errors.cc index f82054c339b493..9d038e3d1683e7 100644 --- a/src/node_errors.cc +++ b/src/node_errors.cc @@ -242,12 +242,11 @@ void AppendExceptionLine(Environment* env, } [[noreturn]] void Assert(const AssertionInfo& info) { - char name[1024]; - GetHumanReadableProcessName(&name); + std::string name = GetHumanReadableProcessName(); fprintf(stderr, "%s: %s:%s%s Assertion `%s' failed.\n", - name, + name.c_str(), info.file_line, info.function, *info.function ? ":" : "", diff --git a/src/node_internals.h b/src/node_internals.h index abe01e6fed897c..64b4d489e1e184 100644 --- a/src/node_internals.h +++ b/src/node_internals.h @@ -97,7 +97,6 @@ void SignalExit(int signal, siginfo_t* info, void* ucontext); std::string GetProcessTitle(const char* default_title); std::string GetHumanReadableProcessName(); -void GetHumanReadableProcessName(char (*name)[1024]); void InitializeContextRuntime(v8::Local); diff --git a/src/util.cc b/src/util.cc index 2a594d81ecab8e..29bfb5d351e35b 100644 --- a/src/util.cc +++ b/src/util.cc @@ -161,13 +161,6 @@ std::string GetHumanReadableProcessName() { return SPrintF("%s[%d]", GetProcessTitle("Node.js"), uv_os_getpid()); } -void GetHumanReadableProcessName(char (*name)[1024]) { - // Leave room after title for pid, which can be up to 20 digits for 64 bit. - char title[1000] = "Node.js"; - uv_get_process_title(title, sizeof(title)); - snprintf(*name, sizeof(*name), "%s[%d]", title, uv_os_getpid()); -} - std::vector SplitString(const std::string& in, char delim) { std::vector out; if (in.empty())