diff options
author | Jude Melton-Houghton <jwmhjwmh@gmail.com> | 2021-08-02 15:33:45 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-02 21:33:45 +0200 |
commit | e15c55c0667f62f971cc58b7d3fb5f771ea4a68d (patch) | |
tree | da8db4ef645aed3e4e1ae23206d1588705dfa0f8 | |
parent | db5879706d04d3480bc4863ce0c03fa73e5f10c7 (diff) | |
download | mesecons-e15c55c0667f62f971cc58b7d3fb5f771ea4a68d.tar mesecons-e15c55c0667f62f971cc58b7d3fb5f771ea4a68d.tar.gz mesecons-e15c55c0667f62f971cc58b7d3fb5f771ea4a68d.tar.bz2 mesecons-e15c55c0667f62f971cc58b7d3fb5f771ea4a68d.tar.xz mesecons-e15c55c0667f62f971cc58b7d3fb5f771ea4a68d.zip |
Handle getting out-of-bounds bits in get_bit (#574)
The binary state is not padded with zeroes, so they must be inferred.
-rw-r--r-- | mesecons/util.lua | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/mesecons/util.lua b/mesecons/util.lua index 3cdeb64..234775b 100644 --- a/mesecons/util.lua +++ b/mesecons/util.lua @@ -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 |