mirror of
https://github.com/awesomeWM/awesome
synced 2024-11-18 22:06:01 +01:00
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
75ad861c7a
commit
c3174f4581
1 changed files with 3 additions and 2 deletions
|
@ -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 a new issue