From 3909e7f6c67ec36d4f1be027ed383e0b2109f48d Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Mon, 3 Dec 2018 09:29:23 +0100 Subject: [PATCH] linux: get rid of strncpy() call While correctly used, it looks suspect and is slightly less efficient because the string is scanned twice for its terminating nul byte. PR-URL: https://github.com/libuv/libuv/pull/2065 Reviewed-By: Refael Ackermann Reviewed-By: Richard Lau --- src/unix/linux-inotify.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/unix/linux-inotify.c b/src/unix/linux-inotify.c index 7797f842..9b26202f 100644 --- a/src/unix/linux-inotify.c +++ b/src/unix/linux-inotify.c @@ -278,6 +278,7 @@ int uv_fs_event_start(uv_fs_event_t* handle, const char* path, unsigned int flags) { struct watcher_list* w; + size_t len; int events; int err; int wd; @@ -306,12 +307,13 @@ int uv_fs_event_start(uv_fs_event_t* handle, if (w) goto no_insert; - w = uv__malloc(sizeof(*w) + strlen(path) + 1); + len = strlen(path) + 1; + w = uv__malloc(sizeof(*w) + len); if (w == NULL) return UV_ENOMEM; w->wd = wd; - w->path = strcpy((char*)(w + 1), path); + w->path = memcpy(w + 1, path, len); QUEUE_INIT(&w->watchers); w->iterating = 0; RB_INSERT(watcher_root, CAST(&handle->loop->inotify_watchers), w);