From e15c55c0667f62f971cc58b7d3fb5f771ea4a68d Mon Sep 17 00:00:00 2001 From: Jude Melton-Houghton Date: Mon, 2 Aug 2021 15:33:45 -0400 Subject: [PATCH] Handle getting out-of-bounds bits in get_bit (#574) The binary state is not padded with zeroes, so they must be inferred. --- mesecons/util.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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