Skip to content

Commit 05317ac

Browse files
correct length
1 parent b4f383b commit 05317ac

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

test/js-native-api/test_string/test_string.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ static napi_status create_external_one_byte(napi_env env,
126126
const size_t length_bytes = (actual_length + 1) * sizeof(*string_copy);
127127
string_copy = malloc(length_bytes);
128128
memcpy(string_copy, string, length_bytes);
129-
string_copy[length] = 0;
129+
string_copy[length_bytes - 1] = 0;
130130

131131
status = create_api(env, string_copy, length, result);
132132
if (status != napi_ok) {
@@ -183,7 +183,7 @@ static napi_status create_external_utf16(napi_env env,
183183
const size_t length_bytes = (actual_length + 1) * sizeof(*string_copy);
184184
string_copy = malloc(length_bytes);
185185
memcpy(string_copy, string, length_bytes);
186-
string_copy[length] = 0;
186+
string_copy[length_bytes - 1] = 0;
187187

188188
status =
189189
node_api_create_external_string_utf16(env, string_copy, length, result);

0 commit comments

Comments
 (0)