From: Guillermo J. Rozas Date: Wed, 17 Jan 1990 19:06:35 +0000 (+0000) Subject: Fix bug in signed-integer->bit-string by which it was not checking X-Git-Tag: 20090517-FFI~11590 X-Git-Url: https://birchwood-abbey.net/git?a=commitdiff_plain;h=d9a7a0541eef2dbe587e267682ebcdd87507e73a;p=mit-scheme.git Fix bug in signed-integer->bit-string by which it was not checking whether the number would fit in the specified number of bits or not. --- diff --git a/v7/src/runtime/bitstr.scm b/v7/src/runtime/bitstr.scm index 62737eedb..ae83e94ec 100644 --- a/v7/src/runtime/bitstr.scm +++ b/v7/src/runtime/bitstr.scm @@ -1,6 +1,6 @@ #| -*-Scheme-*- -$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/runtime/bitstr.scm,v 14.1 1988/06/13 11:40:45 cph Rel $ +$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/runtime/bitstr.scm,v 14.2 1990/01/17 19:06:35 jinx Rel $ Copyright (c) 1988 Massachusetts Institute of Technology @@ -109,7 +109,10 @@ MIT in each case. |# (define (signed-integer->bit-string nbits number) (unsigned-integer->bit-string nbits - (cond ((negative? number) (+ number (expt 2 nbits))) + (cond ((negative? number) + (if (>= number (- (expt 2 (-1+ nbits)))) + (+ number (expt 2 nbits)) + (error "Integer too small to be encoded" number))) ((< number (expt 2 (-1+ nbits))) number) (else (error "Integer too large to be encoded" number)))))