summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJude Melton-Houghton <jwmhjwmh@gmail.com>2021-08-02 15:33:45 -0400
committerGitHub <noreply@github.com>2021-08-02 21:33:45 +0200
commite15c55c0667f62f971cc58b7d3fb5f771ea4a68d (patch)
treeda8db4ef645aed3e4e1ae23206d1588705dfa0f8
parentdb5879706d04d3480bc4863ce0c03fa73e5f10c7 (diff)
downloadmesecons-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.lua4
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