Handle getting out-of-bounds bits in get_bit
The binary state is not padded with zeroes, so they must be inferred.
This commit is contained in:
parent
db5879706d
commit
4205efb6d0
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue