Fixing right shift of a fixnum by > word size.

Fixes bug report from Miroslav Urbanek.
This commit is contained in:
Alex Shinn 2014-02-26 07:16:01 +09:00
parent f5a33c3aa1
commit 91f8516a89
2 changed files with 5 additions and 1 deletions

View file

@ -157,7 +157,7 @@ static sexp sexp_arithmetic_shift (sexp ctx, sexp self, sexp_sint_t n, sexp i, s
if (c == 0) return i; if (c == 0) return i;
if (sexp_fixnump(i)) { if (sexp_fixnump(i)) {
if (c < 0) { if (c < 0) {
res = sexp_make_fixnum(sexp_unbox_fixnum(i) >> -c); res = sexp_make_fixnum(c > -sizeof(sexp_sint_t)*CHAR_BIT ? sexp_unbox_fixnum(i) >> -c : 0);
} else { } else {
#if SEXP_USE_BIGNUMS #if SEXP_USE_BIGNUMS
if ((log2i(sexp_unbox_fixnum(i)) + c + 1) if ((log2i(sexp_unbox_fixnum(i)) + c + 1)

View file

@ -34,4 +34,8 @@
(test (- (expt 2 128)) (arithmetic-shift -1 128)) (test (- (expt 2 128)) (arithmetic-shift -1 128))
(test (- (expt 2 129)) (arithmetic-shift -1 129)) (test (- (expt 2 129)) (arithmetic-shift -1 129))
(test 0 (arithmetic-shift 1 -63))
(test 0 (arithmetic-shift 1 -64))
(test 0 (arithmetic-shift 1 -65))
(test-end) (test-end)