diff --git a/lib/srfi/33/bit.c b/lib/srfi/33/bit.c index 046d779e..0546cc33 100644 --- a/lib/srfi/33/bit.c +++ b/lib/srfi/33/bit.c @@ -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 (sexp_fixnump(i)) { 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 { #if SEXP_USE_BIGNUMS if ((log2i(sexp_unbox_fixnum(i)) + c + 1) diff --git a/tests/srfi-33-tests.scm b/tests/srfi-33-tests.scm index 74eb74d8..d314bd4a 100644 --- a/tests/srfi-33-tests.scm +++ b/tests/srfi-33-tests.scm @@ -34,4 +34,8 @@ (test (- (expt 2 128)) (arithmetic-shift -1 128)) (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)