From c25b209c8b7744916111dc0c4fd0b2a1ddc72352 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Wed, 24 May 2017 15:25:43 +1000 Subject: src/lvm.js: loops with integers should overflow --- src/lvm.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/lvm.js b/src/lvm.js index 0081376..cd197ab 100644 --- a/src/lvm.js +++ b/src/lvm.js @@ -516,7 +516,7 @@ const luaV_execute = function(L) { case OCi.OP_FORLOOP: { if (L.stack[ra].ttisinteger()) { /* integer loop? */ let step = L.stack[ra + 2].value; - let idx = L.stack[ra].value + step; + let idx = (L.stack[ra].value + step)|0; let limit = L.stack[ra + 1].value; if (0 < step ? idx <= limit : limit <= idx) { @@ -547,7 +547,7 @@ const luaV_execute = function(L) { if (init.ttisinteger() && pstep.ttisinteger() && forlim.casted) { /* all values are integer */ let initv = forlim.stopnow ? 0 : init.value; plimit.value = forlim.ilimit; - init.value = initv - pstep.value; + init.value = (initv - pstep.value)|0; } else { /* try making all values floats */ let ninit = tonumber(init); let nlimit = tonumber(plimit); -- cgit v1.2.3-70-g09d2