vis

a vi-like editor based on Plan 9's structural regular expressions

git clone https://9o.is/git/vis.git

commit 4e3f141048fabc68c708bd452459344852961128
parent 92eb5c92ca6f1e665576d0d18c13c881216e0cb5
Author: Randy Palamar <palamar@ualberta.ca>
Date:   Sun, 27 Aug 2023 09:01:01 -0600

vis-lua.c: silence warning about implicit conversion

`SIZE_MAX` cannot be represented accurately in `lua_Number`. A correct
solution probably doesn't exist but we can silence the warning by
explicitly casting to `lua_Number` and changing the comparison to `<`
instead of `<=`.

checkpos() deals with large numbers for file ranges. For most users we
can assume no one is editing files that are `SIZE_MAX` bytes long (many
petabytes). For obscure systems where `SIZE_MAX` is a small number this
will result in a maximum range (in lua) of 1 byte less than before.

fixes #1120: vis-lua.c:504:21: warning: implicit conversion changes value

Diffstat:
Mvis-lua.c | 6+++++-
1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/vis-lua.c b/vis-lua.c @@ -501,7 +501,11 @@ static size_t getpos(lua_State *L, int narg) { static size_t checkpos(lua_State *L, int narg) { lua_Number n = luaL_checknumber(L, narg); - if (n >= 0 && n <= SIZE_MAX && n == (size_t)n) + /* on most systems SIZE_MAX can't be represented in lua_Number. + * using < avoids undefined behaviour when n == SIZE_MAX+1 + * which can be represented in lua_Number + */ + if (n >= 0 && n < (lua_Number)SIZE_MAX && n == (size_t)n) return n; return luaL_argerror(L, narg, "expected position, got number"); }