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:
Jude Melton-Houghton 2021-07-29 10:11:43 -04:00
parent db5879706d
commit 4205efb6d0
1 changed files with 7 additions and 2 deletions

View File

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