summaryrefslogtreecommitdiff
path: root/lauxlib.h
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2021-09-22 13:10:39 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2021-09-22 13:10:39 -0300
commitdeac067ed39a44c001599c0d15de09872496b2aa (patch)
treed7373651e7d54a8ca5ffa4841379a4d9149164aa /lauxlib.h
parent2ff34717227b8046b0fdcb96206f11f5e888664e (diff)
downloadlua-github-deac067ed39a44c001599c0d15de09872496b2aa.tar.gz
Avoid overflows when incrementing parameters in C
Any C function can receive maxinteger as an integer argument, and therefore cannot increment it without some care (e.g., doing unsigned arithmetic as the core does).
Diffstat (limited to 'lauxlib.h')
-rw-r--r--lauxlib.h8
1 files changed, 8 insertions, 0 deletions
diff --git a/lauxlib.h b/lauxlib.h
index 72f70e7d..6f9695e8 100644
--- a/lauxlib.h
+++ b/lauxlib.h
@@ -154,6 +154,14 @@ LUALIB_API void (luaL_requiref) (lua_State *L, const char *modname,
#define luaL_loadbuffer(L,s,sz,n) luaL_loadbufferx(L,s,sz,n,NULL)
+/*
+** Perform arithmetic operations on lua_Integer values with wrap-around
+** semantics, as the Lua core does.
+*/
+#define luaL_intop(op,v1,v2) \
+ ((lua_Integer)((lua_Unsigned)(v1) op (lua_Unsigned)(v2)))
+
+
/* push the value used to represent failure/error */
#define luaL_pushfail(L) lua_pushnil(L)