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/
This commit is contained in:
Amal Raj T 2020-08-01 12:38:45 +05:30
parent 25a5d69ee6
commit dc6fdcd7a0
2 changed files with 5 additions and 4 deletions

View File

@ -350,7 +350,7 @@ static int uv__fs_mkstemp(uv_fs_t* req) {
clobber:
if (r < 0)
*(path) = '\0';
path[0] = '\0';
return r;
}

View File

@ -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';
}