diff --git a/lib/srfi/33/bit.c b/lib/srfi/33/bit.c index 0546cc33..995d4da7 100644 --- a/lib/srfi/33/bit.c +++ b/lib/srfi/33/bit.c @@ -202,7 +202,8 @@ static sexp sexp_arithmetic_shift (sexp ctx, sexp self, sexp_sint_t n, sexp i, s for (j=tmp=0; j> tail_shift; + if (bit_shift != 0) + tmp = sexp_bignum_data(i)[j] >> tail_shift; } if (bit_shift != 0) sexp_bignum_data(res)[len+offset] = tmp; } @@ -286,20 +287,24 @@ static sexp sexp_integer_length (sexp ctx, sexp self, sexp_sint_t n, sexp x) { } static sexp sexp_bit_set_p (sexp ctx, sexp self, sexp_sint_t n, sexp i, sexp x) { + sexp_sint_t pos; #if SEXP_USE_BIGNUMS - sexp_uint_t pos; + sexp_sint_t rem; #endif if (! sexp_fixnump(i)) return sexp_type_exception(ctx, self, SEXP_FIXNUM, i); + pos = sexp_unbox_fixnum(i); + if (pos < 0) + return sexp_xtype_exception(ctx, self, "index must be non-negative", i); if (sexp_fixnump(x)) { - return sexp_make_boolean(sexp_unbox_fixnum(x) & (1UL<