lua

A copy of the Lua development repository
Log | Files | Refs | README

commit f055a9dffd9ba403a99266a662b9992bc89dcaa1
parent 4a7fe61806b266d895c0d2a4725dc427315022bb
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date:   Sun, 25 Feb 2018 09:43:25 -0300

added check in 'obj2gco' to prevent its use in non Lua-object pointers
(otherwise its cast is blind, casting any value given to it)

Diffstat:
Mlstate.h | 9++++++---
1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/lstate.h b/lstate.h @@ -1,5 +1,5 @@ /* -** $Id: lstate.h,v 2.155 2018/02/15 18:06:24 roberto Exp roberto $ +** $Id: lstate.h,v 2.156 2018/02/17 19:29:29 roberto Exp roberto $ ** Global State ** See Copyright Notice in lua.h */ @@ -252,8 +252,11 @@ union GCUnion { #define gco2upv(o) check_exp((o)->tt == LUA_TUPVAL, &((cast_u(o))->upv)) -/* macro to convert a Lua object into a GCObject */ -#define obj2gco(v) (&(cast_u(v)->gc)) +/* +** macro to convert a Lua object into a GCObject +** (The access to 'tt' tries to ensure that 'v' is actually a Lua object.) +*/ +#define obj2gco(v) check_exp((v)->tt >= LUA_TSTRING, &(cast_u(v)->gc)) /* actual number of total bytes allocated */