From dc6fdcd7a0eb6f65eb702216d6a55c540af72f6c Mon Sep 17 00:00:00 2001 From: Amal Raj T Date: Sat, 1 Aug 2020 12:38:45 +0530 Subject: [PATCH] fs: clobber req->path on uv_fs_mkstemp() error Fix issues mentioned by @vtjnash in pull request. path[0] = '\0' is more readable *(path) = '\0' and it is the standard used throghout the codebase. In windows req->path is constant string. So it's casted to char* to make it writable. Ref: https://github.com/libuv/libuv/pull/2933/ --- src/unix/fs.c | 2 +- src/win/fs.c | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/unix/fs.c b/src/unix/fs.c index bcb8e2c5..a89a10c5 100644 --- a/src/unix/fs.c +++ b/src/unix/fs.c @@ -350,7 +350,7 @@ static int uv__fs_mkstemp(uv_fs_t* req) { clobber: if (r < 0) - *(path) = '\0'; + path[0] = '\0'; return r; } diff --git a/src/win/fs.c b/src/win/fs.c index ac20a574..c62eccc5 100644 --- a/src/win/fs.c +++ b/src/win/fs.c @@ -1242,6 +1242,7 @@ void fs__mktemp(uv_fs_t* req, uv__fs_mktemp_func func) { unsigned int tries, i; size_t len; uint64_t v; + char *path = req->path; len = wcslen(req->file.pathw); ep = req->file.pathw + len; @@ -1265,8 +1266,8 @@ void fs__mktemp(uv_fs_t* req, uv__fs_mktemp_func func) { if (func(req)) { if (req->result >= 0) { - len = strlen(req->path); - wcstombs((char*) req->path + len - num_x, ep - num_x, num_x); + len = strlen(path); + wcstombs(path + len - num_x, ep - num_x, num_x); } return; } @@ -1275,7 +1276,7 @@ void fs__mktemp(uv_fs_t* req, uv__fs_mktemp_func func) { SET_REQ_RESULT(req, -1); clobber: - (char) *(req->path) = '\0'; + path[0] = '\0'; }