lua

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

commit 7ceb2154ed69170f3e47f7a5a840e543c7c6ed3d
parent 23e6bac8a0bbb9e5df43cbc0b7634b6d1395b0ff
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date:   Mon, 25 Mar 2019 10:38:29 -0300

Fixed small bugs/issues

- In 'readutf8esc' (llex.c), the overflow check must be done before
shifting the accumulator. It was working because tests were using
64-bit longs. Failed with 32-bit longs.

- In OP_FORPREP (lvm.c), avoid negating an unsigned value. Visual
Studio gives a warning for that operation, despite being well
defined in ISO C.

- In 'luaV_execute' (lvm.c), 'cond' can be defined only when needed,
like all other variables.

Diffstat:
Mllex.c | 2+-
Mlvm.c | 12++++++++----
2 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/llex.c b/llex.c @@ -334,8 +334,8 @@ static unsigned long readutf8esc (LexState *ls) { r = gethexa(ls); /* must have at least one digit */ while ((save_and_next(ls), lisxdigit(ls->current))) { i++; + esccheck(ls, r <= (0x7FFFFFFFu >> 4), "UTF-8 value too large"); r = (r << 4) + luaO_hexavalue(ls->current); - esccheck(ls, r <= 0x7FFFFFFFu, "UTF-8 value too large"); } esccheck(ls, ls->current == '}', "missing '}'"); next(ls); /* skip '}' */ diff --git a/lvm.c b/lvm.c @@ -925,6 +925,7 @@ void luaV_finishOp (lua_State *L) { ** Order operations with register operands. */ #define op_order(L,opi,opf,other) { \ + int cond; \ TValue *rb = vRB(i); \ if (ttisinteger(s2v(ra)) && ttisinteger(rb)) \ cond = opi(ivalue(s2v(ra)), ivalue(rb)); \ @@ -939,6 +940,7 @@ void luaV_finishOp (lua_State *L) { ** Order operations with immediate operand. */ #define op_orderI(L,opi,opf,inv,tm) { \ + int cond; \ int im = GETARG_sB(i); \ if (ttisinteger(s2v(ra))) \ cond = opi(ivalue(s2v(ra)), im); \ @@ -1076,7 +1078,6 @@ void luaV_execute (lua_State *L, CallInfo *ci) { base = ci->func + 1; /* main loop of interpreter */ for (;;) { - int cond; /* flag for conditional jumps */ Instruction i; /* instruction being executed */ StkId ra; /* instruction's A register */ vmfetch(); @@ -1475,6 +1476,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) { vmbreak; } vmcase(OP_EQ) { + int cond; TValue *rb = vRB(i); Protect(cond = luaV_equalobj(L, s2v(ra), rb)); docondjump(); @@ -1491,11 +1493,12 @@ void luaV_execute (lua_State *L, CallInfo *ci) { vmcase(OP_EQK) { TValue *rb = KB(i); /* basic types do not use '__eq'; we can use raw equality */ - cond = luaV_equalobj(NULL, s2v(ra), rb); + int cond = luaV_equalobj(NULL, s2v(ra), rb); docondjump(); vmbreak; } vmcase(OP_EQI) { + int cond; int im = GETARG_sB(i); if (ttisinteger(s2v(ra))) cond = (ivalue(s2v(ra)) == im); @@ -1523,7 +1526,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) { vmbreak; } vmcase(OP_TEST) { - cond = !l_isfalse(s2v(ra)); + int cond = !l_isfalse(s2v(ra)); docondjump(); vmbreak; } @@ -1679,7 +1682,8 @@ void luaV_execute (lua_State *L, CallInfo *ci) { } else { /* step < 0; descending loop */ count = l_castS2U(init) - l_castS2U(limit); - count /= -l_castS2U(step); + /* 'step+1' avoids negating 'mininteger' */ + count /= l_castS2U(-(step + 1)) + 1u; } /* store the counter in place of the limit (which won't be needed anymore */