Skip to content

Commit 482ce6c

Browse files
Gabriel SchulhofMylesBorins
Gabriel Schulhof
authored andcommitted
doc: improve N-API string-to-native doc
Mention null termination handling in the string size accounting and string truncation. PR-URL: #35322 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Michael Dawson <[email protected]>
1 parent 6dc6dad commit 482ce6c

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

doc/api/n-api.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3077,9 +3077,10 @@ napi_status napi_get_value_string_latin1(napi_env env,
30773077
* `[in] env`: The environment that the API is invoked under.
30783078
* `[in] value`: `napi_value` representing JavaScript string.
30793079
* `[in] buf`: Buffer to write the ISO-8859-1-encoded string into. If `NULL` is
3080-
passed in, the length of the string (in bytes) is returned.
3080+
passed in, the length of the string in bytes and excluding the null terminator
3081+
is returned in `result`.
30813082
* `[in] bufsize`: Size of the destination buffer. When this value is
3082-
insufficient, the returned string will be truncated.
3083+
insufficient, the returned string will be truncated and null-terminated.
30833084
* `[out] result`: Number of bytes copied into the buffer, excluding the null
30843085
terminator.
30853086

@@ -3106,9 +3107,10 @@ napi_status napi_get_value_string_utf8(napi_env env,
31063107
* `[in] env`: The environment that the API is invoked under.
31073108
* `[in] value`: `napi_value` representing JavaScript string.
31083109
* `[in] buf`: Buffer to write the UTF8-encoded string into. If `NULL` is passed
3109-
in, the length of the string (in bytes) is returned.
3110+
in, the length of the string in bytes and excluding the null terminator is
3111+
returned in `result`.
31103112
* `[in] bufsize`: Size of the destination buffer. When this value is
3111-
insufficient, the returned string will be truncated.
3113+
insufficient, the returned string will be truncated and null-terminated.
31123114
* `[out] result`: Number of bytes copied into the buffer, excluding the null
31133115
terminator.
31143116

@@ -3134,9 +3136,10 @@ napi_status napi_get_value_string_utf16(napi_env env,
31343136
* `[in] env`: The environment that the API is invoked under.
31353137
* `[in] value`: `napi_value` representing JavaScript string.
31363138
* `[in] buf`: Buffer to write the UTF16-LE-encoded string into. If `NULL` is
3137-
passed in, the length of the string (in 2-byte code units) is returned.
3139+
passed in, the length of the string in 2-byte code units and excluding the
3140+
null terminator is returned.
31383141
* `[in] bufsize`: Size of the destination buffer. When this value is
3139-
insufficient, the returned string will be truncated.
3142+
insufficient, the returned string will be truncated and null-terminated.
31403143
* `[out] result`: Number of 2-byte code units copied into the buffer, excluding
31413144
the null terminator.
31423145

0 commit comments

Comments
 (0)