From 59fd0c4132f06a76c460f46ec93fce7b7f1d6f08 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Thu, 26 Jan 2017 14:33:03 +0100 Subject: refactor: Remove strncpy/STRNCPY. (#6008) Closes #731 References #851 Note: This does not remove some intentional legacy usages of strncpy. - memcpy isn't equivalent because it doesn't check the string length of `src`, and doesn't zero-out the remainder of `dst`. - xstrlcpy isn't equivalent because it doesn't zero-out the remainder of `dst`. Some Vim logic depends on that (e.g. ex_append which calls vim_strnsave). Helped-by: Douglas Schneider Helped-by: oni-link Helped-by: James McCoy --- src/nvim/os/env.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'src/nvim/os/env.c') diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c index 109b5c7175..747a34d8ce 100644 --- a/src/nvim/os/env.c +++ b/src/nvim/os/env.c @@ -112,11 +112,11 @@ int64_t os_get_pid(void) #endif } -/// Get the hostname of the machine running Neovim. +/// Gets the hostname of the current machine. /// -/// @param hostname Buffer to store the hostname. -/// @param len Length of `hostname`. -void os_get_hostname(char *hostname, size_t len) +/// @param hostname Buffer to store the hostname. +/// @param size Size of `hostname`. +void os_get_hostname(char *hostname, size_t size) { #ifdef HAVE_SYS_UTSNAME_H struct utsname vutsname; @@ -124,8 +124,7 @@ void os_get_hostname(char *hostname, size_t len) if (uname(&vutsname) < 0) { *hostname = '\0'; } else { - strncpy(hostname, vutsname.nodename, len - 1); - hostname[len - 1] = '\0'; + xstrlcpy(hostname, vutsname.nodename, size); } #else // TODO(unknown): Implement this for windows. -- cgit