From: Chris Hanson Date: Thu, 24 Sep 2009 07:08:42 +0000 (-0700) Subject: Don't accept negative integers when converting to ulong. X-Git-Tag: 20100708-Gtk~316^2~4 X-Git-Url: https://birchwood-abbey.net/git?a=commitdiff_plain;h=8f5433e480b9b0371589b82990391656c7dba12a;p=mit-scheme.git Don't accept negative integers when converting to ulong. --- diff --git a/src/microcode/artutl.c b/src/microcode/artutl.c index 275b8de50..cd6addc5f 100644 --- a/src/microcode/artutl.c +++ b/src/microcode/artutl.c @@ -70,7 +70,7 @@ long_to_integer (long number) bool integer_to_ulong_p (SCHEME_OBJECT n) { - return ((FIXNUM_P (n)) || (BIGNUM_TO_ULONG_P (n))); + return ((FIXNUM_P (n)) ? (!FIXNUM_NEGATIVE_P (n)) : (BIGNUM_TO_ULONG_P (n))); } unsigned long diff --git a/src/microcode/bignum.c b/src/microcode/bignum.c index bb3b8ca1b..ad8e3e052 100644 --- a/src/microcode/bignum.c +++ b/src/microcode/bignum.c @@ -425,13 +425,6 @@ bignum_remainder (bignum_type numerator, bignum_type denominator) } } -/* These procedures depend on the non-portable type `unsigned long'. - If your compiler doesn't support this type, either define the - switch `BIGNUM_NO_ULONG' to disable them (in "bignum.h"), or write - new versions that don't use this type. */ - -#ifndef BIGNUM_NO_ULONG - bignum_type long_to_bignum (long n) { @@ -513,6 +506,7 @@ bignum_to_ulong (bignum_type bignum) { if (BIGNUM_ZERO_P (bignum)) return (0); + BIGNUM_ASSERT (BIGNUM_POSITIVE_P (bignum)); { unsigned long accumulator = 0; bignum_digit_type * start = (BIGNUM_START_PTR (bignum)); @@ -522,8 +516,6 @@ bignum_to_ulong (bignum_type bignum) return (accumulator); } } - -#endif /* not BIGNUM_NO_ULONG */ #define DTB_WRITE_DIGIT(n_bits) do \ { \ @@ -747,7 +739,17 @@ int bignum_fits_in_word_p (bignum_type bignum, long word_length, int twos_complement_p) { - unsigned int n_bits = (twos_complement_p ? (word_length - 1) : word_length); + unsigned int n_bits; + + if (twos_complement_p) + { + if (BIGNUM_NEGATIVE_P (bignum)) + return (0); + n_bits = (word_length - 1); + } + else + n_bits = word_length; + BIGNUM_ASSERT (n_bits > 0); { bignum_length_type length = (BIGNUM_LENGTH (bignum));