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.
This commit is contained in:
Fingercomp 2016-08-09 21:13:50 +07:00
parent 2a5de6868a
commit b95cf7cae9
No known key found for this signature in database
GPG Key ID: BBC71CEE45D86E37

View File

@ -66,9 +66,15 @@ function bit32.replace(n, v, field, width)
end end
function bit32.lrotate(x, disp) function bit32.lrotate(x, disp)
if disp == 0 then return x if disp == 0 then
elseif disp < 0 then return bit32.rrotate(x, -disp) return x
else return trim((x << disp) | (x >> (32 - disp))) end 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 end
function bit32.lshift(x, disp) function bit32.lshift(x, disp)
@ -76,9 +82,15 @@ function bit32.lshift(x, disp)
end end
function bit32.rrotate(x, disp) function bit32.rrotate(x, disp)
if disp == 0 then return x if disp == 0 then
elseif disp < 0 then return bit32.lrotate(x, -disp) return x
else return trim((x >> disp) | (x << (32 - disp))) end 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 end
function bit32.rshift(x, disp) function bit32.rshift(x, disp)