• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Infinite loop in common compat.lua function

Dip Set

Veteran OT User
Joined
Dec 27, 2007
Messages
405
Solutions
2
Reaction score
369
Lua:
function getTileThingByPos(position)
    local t = Tile(position)
    if t == nil then
        if position.stackpos == -1 then
            return -1
        end
        return pushThing(nil)
    end
    if position.stackpos == -1 then
        return t:getThingCount()
    end
    return pushThing(t:getThing(position.stackpos))
end

Using this "possible infinite loop catcher" script from [ANY TFS] Catch scripts that freeze server (https://otland.net/threads/any-tfs-catch-scripts-that-freeze-server.261466/)

I have set the limit to 1,000,000 loops to reduce false positives. This script shows up as a possible infinite loop, specifically here

if t == nil then

I was looking at this code, and realized immediately how this could be easily broken. If this is used in a script, and the tile returns nil (very possible if wrong coordinate), then it will lead to an infinite loop. The reason why I posted this into support is... I'm not sure how this could be avoided.

Any ideas?
 
Back
Top