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:
Perry Hargrave 2011-11-09 12:34:30 -08:00 committed by Uli Schlachter
parent 75ad861c7a
commit c3174f4581

View file

@ -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