Skip to content

Commit

Permalink
os,report: use UV_MAXHOSTNAMESIZE
Browse files Browse the repository at this point in the history
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: #26038
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Richard Lau <[email protected]>
Reviewed-By: Jeremiah Senkpiel <[email protected]>
Reviewed-By: Sakthipriyan Vairamani <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
cjihrig authored and addaleax committed Feb 13, 2019
1 parent 8495a78 commit 5f6a710
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 18 deletions.
9 changes: 1 addition & 8 deletions src/node_os.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,10 @@

#ifdef __POSIX__
# include <limits.h> // PATH_MAX on Solaris.
# include <netdb.h> // MAXHOSTNAMELEN on Solaris.
# include <unistd.h> // gethostname, sysconf
# include <sys/param.h> // MAXHOSTNAMELEN on Linux and the BSDs.
# include <sys/utsname.h>
#endif // __POSIX__

// Add Windows fallback.
#ifndef MAXHOSTNAMELEN
# define MAXHOSTNAMELEN 256
#endif // MAXHOSTNAMELEN

namespace node {
namespace os {

Expand All @@ -67,7 +60,7 @@ using v8::Value;

static void GetHostname(const FunctionCallbackInfo<Value>& 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);

Expand Down
11 changes: 1 addition & 10 deletions src/node_report.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,6 @@
extern char** environ;
#endif

#ifdef __POSIX__
# include <netdb.h> // MAXHOSTNAMELEN on Solaris.
# include <sys/param.h> // MAXHOSTNAMELEN on Linux and the BSDs.
#endif // __POSIX__

#ifndef MAXHOSTNAMELEN
# define MAXHOSTNAMELEN 256
#endif // MAXHOSTNAMELEN

namespace report {
using node::arraysize;
using node::Environment;
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 5f6a710

Please sign in to comment.