diff options
author | Michael Lingelbach <m.j.lbach@gmail.com> | 2021-12-15 09:07:23 -0800 |
---|---|---|
committer | Michael Lingelbach <m.j.lbach@gmail.com> | 2021-12-15 09:07:23 -0800 |
commit | 1a887293ef66b51220d40f8f91dfc8245f8aeec5 (patch) | |
tree | e6d891ee0a77905c3b60bb7bd6228782654b7282 /src/nvim/lua/stdlib.c | |
parent | 2fe60905f6e12b3cae5c9ca2d1456fe23501be61 (diff) | |
download | rneovim-1a887293ef66b51220d40f8f91dfc8245f8aeec5.tar.gz rneovim-1a887293ef66b51220d40f8f91dfc8245f8aeec5.tar.bz2 rneovim-1a887293ef66b51220d40f8f91dfc8245f8aeec5.zip |
fix: do not cast offset to char_u
* str_utf_start/end both cast the offset into the utf string
to a char_u, a pointer + long is well-defined and the cast is
unnecessary. This previously resulted in issues for offsets greater than
256.
Diffstat (limited to 'src/nvim/lua/stdlib.c')
-rw-r--r-- | src/nvim/lua/stdlib.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/nvim/lua/stdlib.c b/src/nvim/lua/stdlib.c index b5553060a1..e7dba12392 100644 --- a/src/nvim/lua/stdlib.c +++ b/src/nvim/lua/stdlib.c @@ -231,7 +231,7 @@ static int nlua_str_utf_start(lua_State *const lstate) FUNC_ATTR_NONNULL_ALL if (offset < 0 || offset > (intptr_t)s1_len) { return luaL_error(lstate, "index out of range"); } - int tail_offset = mb_head_off((char_u *)s1, (char_u *)s1 + (char_u)offset - 1); + int tail_offset = mb_head_off((char_u *)s1, (char_u *)s1 + offset - 1); lua_pushinteger(lstate, tail_offset); return 1; } @@ -251,7 +251,7 @@ static int nlua_str_utf_end(lua_State *const lstate) FUNC_ATTR_NONNULL_ALL if (offset < 0 || offset > (intptr_t)s1_len) { return luaL_error(lstate, "index out of range"); } - int tail_offset = mb_tail_off((char_u *)s1, (char_u *)s1 + (char_u)offset - 1); + int tail_offset = mb_tail_off((char_u *)s1, (char_u *)s1 + offset - 1); lua_pushinteger(lstate, tail_offset); return 1; } |