diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-03-25 10:38:56 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-03-25 10:38:56 -0300 |
commit | 7ceb2154ed69170f3e47f7a5a840e543c7c6ed3d (patch) | |
tree | 0db256dfe578fee0a88db6c887b40c3e262055a8 /lvm.c | |
parent | 23e6bac8a0bbb9e5df43cbc0b7634b6d1395b0ff (diff) | |
download | lua-7ceb2154ed69170f3e47f7a5a840e543c7c6ed3d.tar.gz lua-7ceb2154ed69170f3e47f7a5a840e543c7c6ed3d.tar.bz2 lua-7ceb2154ed69170f3e47f7a5a840e543c7c6ed3d.zip |
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 (limited to 'lvm.c')
-rw-r--r-- | lvm.c | 12 |
1 files changed, 8 insertions, 4 deletions
@@ -925,6 +925,7 @@ void luaV_finishOp (lua_State *L) { | |||
925 | ** Order operations with register operands. | 925 | ** Order operations with register operands. |
926 | */ | 926 | */ |
927 | #define op_order(L,opi,opf,other) { \ | 927 | #define op_order(L,opi,opf,other) { \ |
928 | int cond; \ | ||
928 | TValue *rb = vRB(i); \ | 929 | TValue *rb = vRB(i); \ |
929 | if (ttisinteger(s2v(ra)) && ttisinteger(rb)) \ | 930 | if (ttisinteger(s2v(ra)) && ttisinteger(rb)) \ |
930 | cond = opi(ivalue(s2v(ra)), ivalue(rb)); \ | 931 | cond = opi(ivalue(s2v(ra)), ivalue(rb)); \ |
@@ -939,6 +940,7 @@ void luaV_finishOp (lua_State *L) { | |||
939 | ** Order operations with immediate operand. | 940 | ** Order operations with immediate operand. |
940 | */ | 941 | */ |
941 | #define op_orderI(L,opi,opf,inv,tm) { \ | 942 | #define op_orderI(L,opi,opf,inv,tm) { \ |
943 | int cond; \ | ||
942 | int im = GETARG_sB(i); \ | 944 | int im = GETARG_sB(i); \ |
943 | if (ttisinteger(s2v(ra))) \ | 945 | if (ttisinteger(s2v(ra))) \ |
944 | cond = opi(ivalue(s2v(ra)), im); \ | 946 | cond = opi(ivalue(s2v(ra)), im); \ |
@@ -1076,7 +1078,6 @@ void luaV_execute (lua_State *L, CallInfo *ci) { | |||
1076 | base = ci->func + 1; | 1078 | base = ci->func + 1; |
1077 | /* main loop of interpreter */ | 1079 | /* main loop of interpreter */ |
1078 | for (;;) { | 1080 | for (;;) { |
1079 | int cond; /* flag for conditional jumps */ | ||
1080 | Instruction i; /* instruction being executed */ | 1081 | Instruction i; /* instruction being executed */ |
1081 | StkId ra; /* instruction's A register */ | 1082 | StkId ra; /* instruction's A register */ |
1082 | vmfetch(); | 1083 | vmfetch(); |
@@ -1475,6 +1476,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) { | |||
1475 | vmbreak; | 1476 | vmbreak; |
1476 | } | 1477 | } |
1477 | vmcase(OP_EQ) { | 1478 | vmcase(OP_EQ) { |
1479 | int cond; | ||
1478 | TValue *rb = vRB(i); | 1480 | TValue *rb = vRB(i); |
1479 | Protect(cond = luaV_equalobj(L, s2v(ra), rb)); | 1481 | Protect(cond = luaV_equalobj(L, s2v(ra), rb)); |
1480 | docondjump(); | 1482 | docondjump(); |
@@ -1491,11 +1493,12 @@ void luaV_execute (lua_State *L, CallInfo *ci) { | |||
1491 | vmcase(OP_EQK) { | 1493 | vmcase(OP_EQK) { |
1492 | TValue *rb = KB(i); | 1494 | TValue *rb = KB(i); |
1493 | /* basic types do not use '__eq'; we can use raw equality */ | 1495 | /* basic types do not use '__eq'; we can use raw equality */ |
1494 | cond = luaV_equalobj(NULL, s2v(ra), rb); | 1496 | int cond = luaV_equalobj(NULL, s2v(ra), rb); |
1495 | docondjump(); | 1497 | docondjump(); |
1496 | vmbreak; | 1498 | vmbreak; |
1497 | } | 1499 | } |
1498 | vmcase(OP_EQI) { | 1500 | vmcase(OP_EQI) { |
1501 | int cond; | ||
1499 | int im = GETARG_sB(i); | 1502 | int im = GETARG_sB(i); |
1500 | if (ttisinteger(s2v(ra))) | 1503 | if (ttisinteger(s2v(ra))) |
1501 | cond = (ivalue(s2v(ra)) == im); | 1504 | cond = (ivalue(s2v(ra)) == im); |
@@ -1523,7 +1526,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) { | |||
1523 | vmbreak; | 1526 | vmbreak; |
1524 | } | 1527 | } |
1525 | vmcase(OP_TEST) { | 1528 | vmcase(OP_TEST) { |
1526 | cond = !l_isfalse(s2v(ra)); | 1529 | int cond = !l_isfalse(s2v(ra)); |
1527 | docondjump(); | 1530 | docondjump(); |
1528 | vmbreak; | 1531 | vmbreak; |
1529 | } | 1532 | } |
@@ -1679,7 +1682,8 @@ void luaV_execute (lua_State *L, CallInfo *ci) { | |||
1679 | } | 1682 | } |
1680 | else { /* step < 0; descending loop */ | 1683 | else { /* step < 0; descending loop */ |
1681 | count = l_castS2U(init) - l_castS2U(limit); | 1684 | count = l_castS2U(init) - l_castS2U(limit); |
1682 | count /= -l_castS2U(step); | 1685 | /* 'step+1' avoids negating 'mininteger' */ |
1686 | count /= l_castS2U(-(step + 1)) + 1u; | ||
1683 | } | 1687 | } |
1684 | /* store the counter in place of the limit (which won't be | 1688 | /* store the counter in place of the limit (which won't be |
1685 | needed anymore */ | 1689 | needed anymore */ |