Skip to content

Commit

Permalink
correct length
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielschulhof committed Jun 7, 2023
1 parent b4f383b commit 05317ac
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions test/js-native-api/test_string/test_string.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ static napi_status create_external_one_byte(napi_env env,
const size_t length_bytes = (actual_length + 1) * sizeof(*string_copy);
string_copy = malloc(length_bytes);
memcpy(string_copy, string, length_bytes);
string_copy[length] = 0;
string_copy[length_bytes - 1] = 0;

status = create_api(env, string_copy, length, result);
if (status != napi_ok) {
Expand Down Expand Up @@ -183,7 +183,7 @@ static napi_status create_external_utf16(napi_env env,
const size_t length_bytes = (actual_length + 1) * sizeof(*string_copy);
string_copy = malloc(length_bytes);
memcpy(string_copy, string, length_bytes);
string_copy[length] = 0;
string_copy[length_bytes - 1] = 0;

status =
node_api_create_external_string_utf16(env, string_copy, length, result);
Expand Down

0 comments on commit 05317ac

Please sign in to comment.