Skip to content

Commit 8ecf313

Browse files
committed
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: #26038 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 0109e12 commit 8ecf313

File tree

2 files changed

+2
-18
lines changed

2 files changed

+2
-18
lines changed

src/node_os.cc

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,9 @@
3333

3434
#ifdef __POSIX__
3535
# include <limits.h> // PATH_MAX on Solaris.
36-
# include <netdb.h> // MAXHOSTNAMELEN on Solaris.
3736
# include <unistd.h> // gethostname, sysconf
38-
# include <sys/param.h> // MAXHOSTNAMELEN on Linux and the BSDs.
3937
#endif // __POSIX__
4038

41-
// Add Windows fallback.
42-
#ifndef MAXHOSTNAMELEN
43-
# define MAXHOSTNAMELEN 256
44-
#endif // MAXHOSTNAMELEN
45-
4639
namespace node {
4740
namespace os {
4841

@@ -66,7 +59,7 @@ using v8::Value;
6659

6760
static void GetHostname(const FunctionCallbackInfo<Value>& args) {
6861
Environment* env = Environment::GetCurrent(args);
69-
char buf[MAXHOSTNAMELEN + 1];
62+
char buf[UV_MAXHOSTNAMESIZE];
7063
size_t size = sizeof(buf);
7164
int r = uv_os_gethostname(buf, &size);
7265

src/node_report.cc

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,6 @@
4747
extern char** environ;
4848
#endif
4949

50-
#ifdef __POSIX__
51-
# include <netdb.h> // MAXHOSTNAMELEN on Solaris.
52-
# include <sys/param.h> // MAXHOSTNAMELEN on Linux and the BSDs.
53-
#endif // __POSIX__
54-
55-
#ifndef MAXHOSTNAMELEN
56-
# define MAXHOSTNAMELEN 256
57-
#endif // MAXHOSTNAMELEN
58-
5950
namespace report {
6051
using node::arraysize;
6152
using node::Environment;
@@ -377,7 +368,7 @@ static void PrintVersionInformation(JSONWriter* writer) {
377368
writer->json_keyvalue("osMachine", os_info.machine);
378369
}
379370

380-
char host[MAXHOSTNAMELEN + 1];
371+
char host[UV_MAXHOSTNAMESIZE];
381372
size_t host_size = sizeof(host);
382373

383374
if (uv_os_gethostname(host, &host_size) == 0)

0 commit comments

Comments
 (0)