From 482ce6ce1d5237117709b5ec0a569ee7b379bd06 Mon Sep 17 00:00:00 2001 From: Gabriel Schulhof Date: Wed, 23 Sep 2020 12:44:47 -0700 Subject: [PATCH] doc: improve N-API string-to-native doc Mention null termination handling in the string size accounting and string truncation. PR-URL: https://github.com/nodejs/node/pull/35322 Reviewed-By: Anna Henningsen Reviewed-By: Michael Dawson --- 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 18f8a596029f56..2415bc55a9cd0e 100644 --- a/doc/api/n-api.md +++ b/doc/api/n-api.md @@ -3077,9 +3077,10 @@ napi_status napi_get_value_string_latin1(napi_env env, * `[in] env`: The environment that the API is invoked under. * `[in] value`: `napi_value` representing JavaScript string. * `[in] buf`: Buffer to write the ISO-8859-1-encoded string into. If `NULL` is - passed in, the length of the string (in bytes) is returned. + 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 will be truncated. + insufficient, the returned string will be truncated and null-terminated. * `[out] result`: Number of bytes copied into the buffer, excluding the null terminator. @@ -3106,9 +3107,10 @@ napi_status napi_get_value_string_utf8(napi_env env, * `[in] env`: The environment that the API is invoked under. * `[in] value`: `napi_value` representing JavaScript string. * `[in] buf`: Buffer to write the UTF8-encoded string into. If `NULL` is passed - in, the length of the string (in bytes) is returned. + 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 will be truncated. + insufficient, the returned string will be truncated and null-terminated. * `[out] result`: Number of bytes copied into the buffer, excluding the null terminator. @@ -3134,9 +3136,10 @@ napi_status napi_get_value_string_utf16(napi_env env, * `[in] env`: The environment that the API is invoked under. * `[in] value`: `napi_value` representing JavaScript string. * `[in] buf`: Buffer to write the UTF16-LE-encoded string into. If `NULL` is - passed in, the length of the string (in 2-byte code units) is returned. + 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 will be truncated. + insufficient, the returned string will be truncated and null-terminated. * `[out] result`: Number of 2-byte code units copied into the buffer, excluding the null terminator.