Skip to content

Commit

Permalink
f
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaozg committed Oct 10, 2024
1 parent 2fb71b8 commit 5d77d1c
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -808,11 +808,11 @@ static int luv_utf16_to_wtf8(lua_State *L) {
const uint16_t *utf16 = (const uint16_t *)luaL_checklstring(L, 1, &sz);
ssize_t utf16_len = luaL_optinteger(L, 2, sz/2);
/* pad NUL terminator */
uint16_t *ws = malloc(sz+2);
if (ws== NULL) return luaL_error(L, "failed to allocate %zu bytes", sz + 2);
memcpy(ws, utf16, sz);
ws[sz/2] = 0;
sz = uv_utf16_length_as_wtf8(utf16, utf16_len);
uint16_t *ws = malloc(2*(utf16_len+1));
if (ws== NULL) return luaL_error(L, "failed to allocate %zu bytes", 2*(utf16_len+1));
memcpy(ws, utf16, 2*utf16_len);
ws[utf16_len] = 0;
sz = uv_utf16_length_as_wtf8(utf16, utf16_len+1);
wtf8 = malloc(sz + 1);
if (wtf8 == NULL) return luaL_error(L, "failed to allocate %zu bytes", sz + 1);
ret = uv_utf16_to_wtf8(ws, utf16_len+1, &wtf8, &sz);
Expand Down

0 comments on commit 5d77d1c

Please sign in to comment.