[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [PATCH] Loop Overflow Bug Fix
- From: Paige DePol <lual@...>
- Date: Wed, 15 Nov 2017 19:18:13 -0600
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)
reps = 0
for i=math.maxinteger,math.mininteger,-math.maxinteger do reps = reps + 1 end
assert(reps == 1)
reps = 0
for i=math.mininteger,math.maxinteger,math.maxinteger/2 do reps = reps + 1 end
assert(reps == 5)
reps = 0
for i=math.maxinteger,math.mininteger,-math.maxinteger/2 do reps = reps + 1 end
assert(reps == 5)
All works as expected! :)
~Paige