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.
diff --git a/llex.c b/llex.c
index 1539f52..b0bab37 100644
--- a/llex.c
+++ b/llex.c
@@ -334,8 +334,8 @@
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
index 47bc67c..d035814 100644
--- a/lvm.c
+++ b/lvm.c
@@ -925,6 +925,7 @@
** 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 @@
** 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 @@
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 @@
vmbreak;
}
vmcase(OP_EQ) {
+ int cond;
TValue *rb = vRB(i);
Protect(cond = luaV_equalobj(L, s2v(ra), rb));
docondjump();
@@ -1491,11 +1493,12 @@
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 @@
vmbreak;
}
vmcase(OP_TEST) {
- cond = !l_isfalse(s2v(ra));
+ int cond = !l_isfalse(s2v(ra));
docondjump();
vmbreak;
}
@@ -1679,7 +1682,8 @@
}
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 */