diff options
author | Michael Lingelbach <m.j.lbach@gmail.com> | 2021-11-27 10:07:58 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-27 10:07:58 -0500 |
commit | 512ec4632fa978dc08753aa26e3bfda7e5ae6868 (patch) | |
tree | 8a80ff1acfc44509cf08502e79e72cd6e9af67a6 /src/nvim/lua/stdlib.c | |
parent | afbf89dc0120b1db5782a0bf807dc7c8db70ccf6 (diff) | |
download | rneovim-512ec4632fa978dc08753aa26e3bfda7e5ae6868.tar.gz rneovim-512ec4632fa978dc08753aa26e3bfda7e5ae6868.tar.bz2 rneovim-512ec4632fa978dc08753aa26e3bfda7e5ae6868.zip |
fix: allow str_utfindex second argument to be an explicit nil (#16448)
* str_utfindex checks number of arguments only, but ignores the case in
which the second argument is an explicit nil. Previously this required
dropping the second argument entirely.
* Modify the C binding to explicitly check if the second argument is nil
Diffstat (limited to 'src/nvim/lua/stdlib.c')
-rw-r--r-- | src/nvim/lua/stdlib.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/nvim/lua/stdlib.c b/src/nvim/lua/stdlib.c index db79e9e7e9..b5553060a1 100644 --- a/src/nvim/lua/stdlib.c +++ b/src/nvim/lua/stdlib.c @@ -175,13 +175,13 @@ int nlua_str_utfindex(lua_State *const lstate) FUNC_ATTR_NONNULL_ALL size_t s1_len; const char *s1 = luaL_checklstring(lstate, 1, &s1_len); intptr_t idx; - if (lua_gettop(lstate) >= 2) { + if (lua_isnoneornil(lstate, 2)) { + idx = (intptr_t)s1_len; + } else { idx = luaL_checkinteger(lstate, 2); if (idx < 0 || idx > (intptr_t)s1_len) { return luaL_error(lstate, "index out of range"); } - } else { - idx = (intptr_t)s1_len; } size_t codepoints = 0, codeunits = 0; |