inet: fix inconsistent return value of inet_ntop6

PR-URL: https://github.com/libuv/libuv/pull/3182
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
This commit is contained in:
twosee 2021-05-27 22:54:33 +08:00 committed by GitHub
parent 4cf638de05
commit 385b7960a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -141,8 +141,9 @@ static int inet_ntop6(const unsigned char *src, char *dst, size_t size) {
if (best.base != -1 && (best.base + best.len) == ARRAY_SIZE(words))
*tp++ = ':';
*tp++ = '\0';
if (UV_E2BIG == uv__strscpy(dst, tmp, size))
if ((size_t) (tp - tmp) > size)
return UV_ENOSPC;
uv__strscpy(dst, tmp, size);
return 0;
}