diff options
| author | ruki <[email protected]> | 2026-01-21 00:54:45 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2026-01-21 00:54:45 +0800 |
| commit | 2eeb428148125962177e2b51a2bb4aa3c95a55ff (patch) | |
| tree | b75bb3b78278818c352ef525954c8ca96afc3062 /core/src | |
| parent | 8a1c05dc44ebc3655299af650dec03204ada9dd8 (diff) | |
fix review issues
Diffstat (limited to 'core/src')
| -rw-r--r-- | core/src/xmake/utf8/codepoint.c | 3 | ||||
| -rw-r--r-- | core/src/xmake/utf8/codes.c | 2 | ||||
| -rw-r--r-- | core/src/xmake/utf8/utf8.c | 3 |
3 files changed, 6 insertions, 2 deletions
diff --git a/core/src/xmake/utf8/codepoint.c b/core/src/xmake/utf8/codepoint.c index 15828a7ab..29aee0f01 100644 --- a/core/src/xmake/utf8/codepoint.c +++ b/core/src/xmake/utf8/codepoint.c @@ -62,9 +62,10 @@ tb_int_t xm_utf8_codepoint(lua_State *lua) { tb_int_t n = (tb_int_t)(pose - posi) + 1; luaL_checkstack(lua, n, "string slice too long"); + int nresults = lua_gettop(lua); if (!xm_utf8_codepoint_impl(s, len, posi, pose, !lax, xm_utf8_codepoint_cb, lua)) { return luaL_error(lua, XM_UTF8_MSGInvalid); } - return n; + return lua_gettop(lua) - nresults; } diff --git a/core/src/xmake/utf8/codes.c b/core/src/xmake/utf8/codes.c index 420584835..bfae6397d 100644 --- a/core/src/xmake/utf8/codes.c +++ b/core/src/xmake/utf8/codes.c @@ -44,7 +44,7 @@ static tb_int_t xm_utf8_codes_iter(lua_State *lua, tb_bool_t strict) { } else { xm_utf8_int_t code; tb_char_t const* next = xm_utf8_decode(s + n, &code, strict); - if (next == NULL || xm_utf8_iscontp(next)) { + if (next == NULL || (next < s + len && xm_utf8_iscontp(next))) { return luaL_error(lua, XM_UTF8_MSGInvalid); } lua_pushinteger(lua, n + 1); diff --git a/core/src/xmake/utf8/utf8.c b/core/src/xmake/utf8/utf8.c index ace3a213c..1e76c2a7e 100644 --- a/core/src/xmake/utf8/utf8.c +++ b/core/src/xmake/utf8/utf8.c @@ -35,6 +35,9 @@ tb_char_t const* xm_utf8_decode(tb_char_t const* s, xm_utf8_int_t* val, tb_bool_ if (c < 0x80) { res = c; } else { + if (xm_utf8_iscont(c)) { + return tb_null; + } tb_int_t count = 0; for (; c & 0x40; c <<= 1) { tb_uint32_t cc = (tb_byte_t)s[++count]; |
