mirror of
https://github.com/minetest-mods/mesecons.git
synced 2024-11-17 15:48:28 +01:00
Handle getting out-of-bounds bits in get_bit (#574)
The binary state is not padded with zeroes, so they must be inferred.
This commit is contained in:
parent
db5879706d
commit
e15c55c066
@ -164,7 +164,9 @@ end
|
||||
|
||||
function mesecon.get_bit(binary,bit)
|
||||
bit = bit or 1
|
||||
local c = binary:len()-(bit-1)
|
||||
local len = binary:len()
|
||||
if bit > len then return false end
|
||||
local c = len-(bit-1)
|
||||
return binary:sub(c,c) == "1"
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user