diff --git a/mesecons/util.lua b/mesecons/util.lua index 3cdeb64..846c995 100644 --- a/mesecons/util.lua +++ b/mesecons/util.lua @@ -163,8 +163,13 @@ function mesecon.getbinstate(nodename, states) end function mesecon.get_bit(binary,bit) - bit = bit or 1 - local c = binary:len()-(bit-1) + local len = binary:len() + if bit then + if bit > len then return false end + else + bit = 1 + end + local c = len-(bit-1) return binary:sub(c,c) == "1" end