Prevent util.cycle from infinite loop (FS#938)
If the first argument to cycle must be > 1 or else return nil immediately. Signed-off-by: Perry Hargrave <resixian@gmail.com> Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
parent
3636b884d3
commit
adbc736b8a
|
@ -50,10 +50,11 @@ function color_strip_alpha(color)
|
|||
end
|
||||
|
||||
--- Make i cycle.
|
||||
-- @param t A length.
|
||||
-- @param t A length. Must be greater than zero.
|
||||
-- @param i An absolute index to fit into #t.
|
||||
-- @return The object at new index.
|
||||
-- @return An integer in (1, t) or nil if t is less than or equal to zero.
|
||||
function cycle(t, i)
|
||||
if t < 1 then return end
|
||||
while i > t do i = i - t end
|
||||
while i < 1 do i = i + t end
|
||||
return i
|
||||
|
|
Loading…
Reference in New Issue