diff --git a/docs/src/misc.rst b/docs/src/misc.rst index bf234dae..ebcb75a2 100644 --- a/docs/src/misc.rst +++ b/docs/src/misc.rst @@ -265,8 +265,9 @@ API `uv_os_homedir()` first checks the `HOME` environment variable using :man:`getenv(3)`. If `HOME` is not set, :man:`getpwuid_r(3)` is called. The user's home directory is stored in `buffer`. When `uv_os_homedir()` is - called, `size` indicates the maximum size of `buffer`. On success or - `UV_ENOBUFS` failure, `size` is set to the string length of `buffer`. + called, `size` indicates the maximum size of `buffer`. On success `size` is set + to the string length of `buffer`. On `UV_ENOBUFS` failure `size` is set to the + required length for `buffer`, including the null byte. .. warning:: `uv_os_homedir()` is not thread safe. @@ -281,8 +282,9 @@ API If none of these are found, the path `"/tmp"` is used, or, on Android, `"/data/local/tmp"` is used. The temp directory is stored in `buffer`. When `uv_os_tmpdir()` is called, `size` indicates the maximum size of `buffer`. - On success or `UV_ENOBUFS` failure, `size` is set to the string length of - `buffer` (which does not include the terminating null). + On success `size` is set to the string length of `buffer` (which does not + include the terminating null). On `UV_ENOBUFS` failure `size` is set to the + required length for `buffer`, including the null byte. .. warning:: `uv_os_tmpdir()` is not thread safe. diff --git a/src/fs-poll.c b/src/fs-poll.c index 570c9547..ee73d5a2 100644 --- a/src/fs-poll.c +++ b/src/fs-poll.c @@ -139,7 +139,7 @@ int uv_fs_poll_getpath(uv_fs_poll_t* handle, char* buffer, size_t* size) { required_len = strlen(ctx->path); if (required_len >= *size) { - *size = required_len; + *size = required_len + 1; return UV_ENOBUFS; } diff --git a/src/unix/core.c b/src/unix/core.c index bcfa1b03..3997d09d 100644 --- a/src/unix/core.c +++ b/src/unix/core.c @@ -1036,7 +1036,7 @@ int uv_os_homedir(char* buffer, size_t* size) { len = strlen(buf); if (len >= *size) { - *size = len; + *size = len + 1; return -ENOBUFS; } @@ -1091,7 +1091,7 @@ int uv_os_homedir(char* buffer, size_t* size) { len = strlen(pw.pw_dir); if (len >= *size) { - *size = len; + *size = len + 1; uv__free(buf); return -ENOBUFS; } @@ -1138,7 +1138,7 @@ return_buffer: len = strlen(buf); if (len >= *size) { - *size = len; + *size = len + 1; return -ENOBUFS; } diff --git a/src/unix/pipe.c b/src/unix/pipe.c index 228f1f77..05d37f46 100644 --- a/src/unix/pipe.c +++ b/src/unix/pipe.c @@ -235,7 +235,7 @@ static int uv__pipe_getsockpeername(const uv_pipe_t* handle, if (addrlen >= *size) { - *size = addrlen; + *size = addrlen + 1; return UV_ENOBUFS; } diff --git a/src/uv-common.c b/src/uv-common.c index 09979536..6b8c584f 100644 --- a/src/uv-common.c +++ b/src/uv-common.c @@ -452,7 +452,7 @@ int uv_fs_event_getpath(uv_fs_event_t* handle, char* buffer, size_t* size) { required_len = strlen(handle->path); if (required_len >= *size) { - *size = required_len; + *size = required_len + 1; return UV_ENOBUFS; } diff --git a/src/win/pipe.c b/src/win/pipe.c index a0948ded..d42bbfec 100644 --- a/src/win/pipe.c +++ b/src/win/pipe.c @@ -2040,7 +2040,7 @@ static int uv__pipe_getname(const uv_pipe_t* handle, char* buffer, size_t* size) goto error; } else if (pipe_prefix_len + addrlen >= *size) { /* "\\\\.\\pipe" + name */ - *size = pipe_prefix_len + addrlen; + *size = pipe_prefix_len + addrlen + 1; err = UV_ENOBUFS; goto error; } diff --git a/src/win/util.c b/src/win/util.c index dbad249b..8cfbd86f 100644 --- a/src/win/util.c +++ b/src/win/util.c @@ -210,7 +210,7 @@ int uv_cwd(char* buffer, size_t* size) { if (r == 0) { return uv_translate_sys_error(GetLastError()); } else if (r > (int) *size) { - *size = r -1; + *size = r; return UV_ENOBUFS; } @@ -1218,7 +1218,7 @@ convert_buffer: if (bufsize == 0) { return uv_translate_sys_error(GetLastError()); } else if (bufsize > *size) { - *size = bufsize - 1; + *size = bufsize; return UV_ENOBUFS; } @@ -1263,7 +1263,7 @@ int uv_os_tmpdir(char* buffer, size_t* size) { if (bufsize == 0) { return uv_translate_sys_error(GetLastError()); } else if (bufsize > *size) { - *size = bufsize - 1; + *size = bufsize; return UV_ENOBUFS; }