From 0e0f77b9f1935831feeec1c412bd497f9e7d7367 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Sun, 4 May 2025 13:29:17 +0100 Subject: [PATCH 1/2] doc: clarify napi_get_value_string_* for bufsize 0 --- doc/api/n-api.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/doc/api/n-api.md b/doc/api/n-api.md index 5548132dd1caf8..9d2844c0de31ac 100644 --- a/doc/api/n-api.md +++ b/doc/api/n-api.md @@ -3688,7 +3688,8 @@ napi_status napi_get_value_string_latin1(napi_env env, passed in, the length of the string in bytes and excluding the null terminator is returned in `result`. * `[in] bufsize`: Size of the destination buffer. When this value is - insufficient, the returned string is truncated and null-terminated. + insufficient, the returned string is truncated and null-terminated if possible, + i.e., it is null-terminated if `bufsize` is not zero. * `[out] result`: Number of bytes copied into the buffer, excluding the null terminator. @@ -3719,7 +3720,8 @@ napi_status napi_get_value_string_utf8(napi_env env, in, the length of the string in bytes and excluding the null terminator is returned in `result`. * `[in] bufsize`: Size of the destination buffer. When this value is - insufficient, the returned string is truncated and null-terminated. + insufficient, the returned string is truncated and null-terminated if possible, + i.e., it is null-terminated if `bufsize` is not zero. * `[out] result`: Number of bytes copied into the buffer, excluding the null terminator. @@ -3749,7 +3751,8 @@ napi_status napi_get_value_string_utf16(napi_env env, passed in, the length of the string in 2-byte code units and excluding the null terminator is returned. * `[in] bufsize`: Size of the destination buffer. When this value is - insufficient, the returned string is truncated and null-terminated. + insufficient, the returned string is truncated and null-terminated if possible, + i.e., it is null-terminated if `bufsize` is not zero. * `[out] result`: Number of 2-byte code units copied into the buffer, excluding the null terminator. From 32bc0ad8d1d947784f54aefbc00e14296e8849ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Mon, 12 May 2025 10:00:24 +0100 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: Vladimir Morozov --- doc/api/n-api.md | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/doc/api/n-api.md b/doc/api/n-api.md index 9d2844c0de31ac..c94d6f6bb5851e 100644 --- a/doc/api/n-api.md +++ b/doc/api/n-api.md @@ -3688,8 +3688,9 @@ napi_status napi_get_value_string_latin1(napi_env env, passed in, the length of the string in bytes and excluding the null terminator is returned in `result`. * `[in] bufsize`: Size of the destination buffer. When this value is - insufficient, the returned string is truncated and null-terminated if possible, - i.e., it is null-terminated if `bufsize` is not zero. + insufficient, the returned string is truncated and null-terminated. + If this value is zero, then the string is not returned and no changes are done + to the buffer. * `[out] result`: Number of bytes copied into the buffer, excluding the null terminator. @@ -3720,8 +3721,9 @@ napi_status napi_get_value_string_utf8(napi_env env, in, the length of the string in bytes and excluding the null terminator is returned in `result`. * `[in] bufsize`: Size of the destination buffer. When this value is - insufficient, the returned string is truncated and null-terminated if possible, - i.e., it is null-terminated if `bufsize` is not zero. + insufficient, the returned string is truncated and null-terminated. + If this value is zero, then the string is not returned and no changes are done + to the buffer. * `[out] result`: Number of bytes copied into the buffer, excluding the null terminator. @@ -3751,8 +3753,9 @@ napi_status napi_get_value_string_utf16(napi_env env, passed in, the length of the string in 2-byte code units and excluding the null terminator is returned. * `[in] bufsize`: Size of the destination buffer. When this value is - insufficient, the returned string is truncated and null-terminated if possible, - i.e., it is null-terminated if `bufsize` is not zero. + insufficient, the returned string is truncated and null-terminated. + If this value is zero, then the string is not returned and no changes are done + to the buffer. * `[out] result`: Number of 2-byte code units copied into the buffer, excluding the null terminator.