From 5f6a710d8dbabfa04e277c9dc95e86e800a3c1e3 Mon Sep 17 00:00:00 2001 From: cjihrig Date: Sun, 10 Feb 2019 12:17:53 -0500 Subject: [PATCH] os,report: use UV_MAXHOSTNAMESIZE UV_MAXHOSTNAMESIZE was introduced in libuv 1.26.0. Use this instead of including multiple header files, adding fallback ifdef logic, and remembering to add one to the buffer size for the terminating nul character with MAXHOSTNAMELEN. PR-URL: https://github.com/nodejs/node/pull/26038 Reviewed-By: Anna Henningsen Reviewed-By: Ben Noordhuis Reviewed-By: Richard Lau Reviewed-By: Jeremiah Senkpiel Reviewed-By: Sakthipriyan Vairamani Reviewed-By: James M Snell --- src/node_os.cc | 9 +-------- src/node_report.cc | 11 +---------- 2 files changed, 2 insertions(+), 18 deletions(-) diff --git a/src/node_os.cc b/src/node_os.cc index a5ae53ba75ee3c..17b507d8e3a37d 100644 --- a/src/node_os.cc +++ b/src/node_os.cc @@ -33,17 +33,10 @@ #ifdef __POSIX__ # include // PATH_MAX on Solaris. -# include // MAXHOSTNAMELEN on Solaris. # include // gethostname, sysconf -# include // MAXHOSTNAMELEN on Linux and the BSDs. # include #endif // __POSIX__ -// Add Windows fallback. -#ifndef MAXHOSTNAMELEN -# define MAXHOSTNAMELEN 256 -#endif // MAXHOSTNAMELEN - namespace node { namespace os { @@ -67,7 +60,7 @@ using v8::Value; static void GetHostname(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); - char buf[MAXHOSTNAMELEN + 1]; + char buf[UV_MAXHOSTNAMESIZE]; size_t size = sizeof(buf); int r = uv_os_gethostname(buf, &size); diff --git a/src/node_report.cc b/src/node_report.cc index 1a459a2d1c97a3..8f882b9887424e 100644 --- a/src/node_report.cc +++ b/src/node_report.cc @@ -47,15 +47,6 @@ extern char** environ; #endif -#ifdef __POSIX__ -# include // MAXHOSTNAMELEN on Solaris. -# include // MAXHOSTNAMELEN on Linux and the BSDs. -#endif // __POSIX__ - -#ifndef MAXHOSTNAMELEN -# define MAXHOSTNAMELEN 256 -#endif // MAXHOSTNAMELEN - namespace report { using node::arraysize; using node::Environment; @@ -377,7 +368,7 @@ static void PrintVersionInformation(JSONWriter* writer) { writer->json_keyvalue("osMachine", os_info.machine); } - char host[MAXHOSTNAMELEN + 1]; + char host[UV_MAXHOSTNAMESIZE]; size_t host_size = sizeof(host); if (uv_os_gethostname(host, &host_size) == 0)