[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: A crash in Lua 5.3.2
- From: Coda Highland <chighland@...>
- Date: Fri, 1 Jan 2016 09:09:29 -0800
On Fri, Jan 1, 2016 at 6:30 AM, Roberto Ierusalimschy
<roberto@inf.puc-rio.br> wrote:
>> > ```
>> > local mt = {}
>> > mt.__newindex = mt
>> > local t = setmetatable({}, mt)
>> > t[1] = 1
>> > ```
>>
>> Right :-( Thanks for the report. Probably it was introduced with the
>> optimizations on table operations; it does not happen in 5.3.1.
>
> The bug is quite subtle. Follows a fix:
>
> diff for lvm.c:
> ----------------------------------------
> 193c193,194
> < lua_assert(ttistable(t) && ttisnil(oldval));
> ---
> > Table *h = hvalue(t);
> > lua_assert(ttisnil(oldval));
> 195c196
> < if ((tm = fasttm(L, hvalue(t)->metatable, TM_NEWINDEX)) == NULL &&
> ---
> > if ((tm = fasttm(L, h->metatable, TM_NEWINDEX)) == NULL &&
> 200c201
> < (oldval = luaH_newkey(L, hvalue(t), key), 1))) {
> ---
> > (oldval = luaH_newkey(L, h, key), 1))) {
> 203,204c204,205
> < invalidateTMcache(hvalue(t));
> < luaC_barrierback(L, hvalue(t), val);
> ---
> > invalidateTMcache(h);
> > luaC_barrierback(L, h, val);
> ----------------------------------------
>
> -- Roberto
>
Oh my, that IS subtle. Good fix!
/s/ Adam