From b95cf7cae9288b0b43db2cd6d7814c7fcd82bc4c Mon Sep 17 00:00:00 2001 From: Fingercomp Date: Tue, 9 Aug 2016 21:13:50 +0700 Subject: [PATCH] fix bit32.lrotate and bit32.rrotate If any of two arguments were too big, those functions returned 0 instead of an expected value. E.g., bit32.lrotate(11111111111111111,2222222222222) --> 0 Expected return value: 3340540761. --- .../opencomputers/loot/openos/lib/bit32.lua | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/main/resources/assets/opencomputers/loot/openos/lib/bit32.lua b/src/main/resources/assets/opencomputers/loot/openos/lib/bit32.lua index 8a05d80f2..67bbcffe3 100644 --- a/src/main/resources/assets/opencomputers/loot/openos/lib/bit32.lua +++ b/src/main/resources/assets/opencomputers/loot/openos/lib/bit32.lua @@ -66,9 +66,15 @@ function bit32.replace(n, v, field, width) end function bit32.lrotate(x, disp) - if disp == 0 then return x - elseif disp < 0 then return bit32.rrotate(x, -disp) - else return trim((x << disp) | (x >> (32 - disp))) end + if disp == 0 then + return x + elseif disp < 0 then + return bit32.rrotate(x, -disp) + else + disp = disp & 31 + x = trim(x) + return trim((x << disp) | (x >> (32 - disp))) + end end function bit32.lshift(x, disp) @@ -76,9 +82,15 @@ function bit32.lshift(x, disp) end function bit32.rrotate(x, disp) - if disp == 0 then return x - elseif disp < 0 then return bit32.lrotate(x, -disp) - else return trim((x >> disp) | (x << (32 - disp))) end + if disp == 0 then + return x + elseif disp < 0 then + return bit32.lrotate(x, -disp) + else + disp = disp & 31 + x = trim(x) + return trim((x >> disp) | (x << (32 - disp))) + end end function bit32.rshift(x, disp)