lua_assert in the wrong place

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

lua_assert in the wrong place

Ahmed Charles
This lua_assert: https://github.com/lua/lua/blob/6bc0f13505bf5d4f613d725fe008c79e72f83ddf/lstring.c#L206

Should be two lines higher, before the call to luaS_hash, which dereferences str unconditionally.
Reply | Threaded
Open this post in threaded view
|

Re: lua_assert in the wrong place

Roberto Ierusalimschy
> This lua_assert: https://github.com/lua/lua/blob/6bc0f13505bf5d4f613d725fe008c79e72f83ddf/lstring.c#L206
>
> Should be two lines higher, before the call to luaS_hash, which dereferences str unconditionally.

'luaS_hash' does not dereference 'str' unconditionally, only when 'l' is
not zero. This assertion exists because 'memcpy' should not be called
with a NULL string even when the length is zero.

-- Roberto
Reply | Threaded
Open this post in threaded view
|

Re: lua_assert in the wrong place

Ahmed Charles
________________________________________
From: Roberto Ierusalimschy <[hidden email]>
Sent: Monday, September 7, 2020 10:55 AM
To: Lua mailing list
Subject: Re: lua_assert in the wrong place

> This lua_assert: https://github.com/lua/lua/blob/6bc0f13505bf5d4f613d725fe008c79e72f83ddf/lstring.c#L206
>
> Should be two lines higher, before the call to luaS_hash, which dereferences str unconditionally.

'luaS_hash' does not dereference 'str' unconditionally, only when 'l' is
not zero. This assertion exists because 'memcpy' should not be called
with a NULL string even when the length is zero.

You're right, sorry about that.