lua-users home
lua-l archive

Re: Specially crafted binary chunks can cause Lua to crash

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


David Given wrote:
Luiz Henrique de Figueiredo wrote:
And we'll probably fix this
Here is the fix:
I find myself using something I've dubbed the 'normalise' operator quite a lot in C and C++ --- !!.
bool convert_to_bool(int i)
{
 return !!i; // equivalent to (i ? true : false)
}
Yes, I know it's just two boolean nots one after the other, but it's sufficiently useful and IMO sufficiently atomic that it's worth thinking of as a primitive operation.
Hopefully your compiler won't optimize that out, and it's not
actually atomic in the sense that it's thread safe :-)
Does the more verbose but clear (i ? true : false) generate better
or worse code in terms of speed or size?
Ralph

AltStyle によって変換されたページ (->オリジナル) /