[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
**Subject**: **Re: [PATCH] Loop Overflow Bug Fix**
**From**: "Soni L." <fakedme@...>
**Date**: Wed, 15 Nov 2017 23:24:05 -0200

On 2017-11-15 11:18 PM, Paige DePol wrote:

Soni L. <fakedme@gmail.com> wrote:

On 2017-11-15 08:34 PM, Paige DePol wrote:

Sorry for the noise... I meant to upload an optimised version of the patch
with the last post to this list! :[
The patch attached to this post has a small optimisation vs the previously
posted patch; the limit check has simply been replaced with the step size
check. This can be done as a limit bounds check is added to OP_FORPREP with
the patch to check if the loop should iterate at all. This new step size
check simply adds one numeric subtraction each loop iteration, well, and a
negation of 'step' for loops with negative step values.
Again, sorry for the noise, this should be the final patch in relation to
fixing the 'for' loop overflows in Lua... hopefully! ;)
~Paige

What happens if you use excessively large loop steps?

Like this?
local reps = 0
for i=math.mininteger,math.maxinteger,math.maxinteger do reps = reps + 1 end
assert(reps == 1)

`Shouldn't this run 3 times, once for i=math.mininteger, once for i=-1,
``once for i=math.maxinteger-1?
`Or do for loops not work as I thought they did?

reps = 0
for i=math.maxinteger,math.mininteger,-math.maxinteger do reps = reps + 1 end
assert(reps == 1)

Idk about this one but it may be wrong too.

reps = 0
for i=math.mininteger,math.maxinteger,math.maxinteger/2 do reps = reps + 1 end
assert(reps == 5)

I have absolutely NO IDEA on this one.

reps = 0
for i=math.maxinteger,math.mininteger,-math.maxinteger/2 do reps = reps + 1 end
assert(reps == 5)

I have absolutely NO IDEA on this one either.

All works as expected! :)
~Paige

--
Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.