mirror of
https://github.com/neovim/neovim.git
synced 2024-12-20 03:05:11 -07:00
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
This commit is contained in:
parent
afbf89dc01
commit
512ec4632f
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user