lua-users home
lua-l archive

Re: Bug in storing -0 constant

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


> I've found a small bug in Lua 5.1.3 (and probably older versions as
> well). The numbers 0 and -0 are treated as identical when used as table
> keys. That's OK, but it leads to a problem when both numbers appear as
> constants in the same function, because the compiler only puts the first
> one into the constant table in the bytecode.
This is a known issue:
 http://lua-users.org/lists/lua-l/2005-01/msg00114.html
Many thanks anyway.
Update: it is not hard to fix this behavior:
--- lcode.c 2008年04月02日 16:16:06 2.35
+++ lcode.c 2008年04月06日 13:31:38
@@ -696,7 +696,7 @@
 e2.t = e2.f = NO_JUMP; e2.k = VKNUM; e2.u.nval = 0;
 switch (op) {
 case OPR_MINUS: {
- if (isnumeral(e)) /* -constant? */
+ if (isnumeral(e) && e->u.nval != 0) /* minus non-zero constant? */
 e->u.nval = luai_numunm(NULL, e->u.nval);
 else {
 luaK_exp2anyreg(fs, e);
-- Roberto

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