From 5345cf7caed5bb1c2ce0772e35df5cf75b61dee1 Mon Sep 17 00:00:00 2001 From: Marius Vollmer Date: Thu, 15 Mar 2001 19:21:51 +0000 Subject: [PATCH] * numbers.c (scm_num2ulong): Check that a bignum is positive before looking at the magnitude. Correctly check for overflow during conversion. --- libguile/numbers.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/libguile/numbers.c b/libguile/numbers.c index 8841dbd50..65d7898cc 100644 --- a/libguile/numbers.c +++ b/libguile/numbers.c @@ -4472,16 +4472,15 @@ scm_num2ulong (SCM num, char *pos, const char *s_caller) } } else if (SCM_BIGP (num)) { unsigned long int res = 0; - unsigned long int old_res = 0; scm_sizet l; + if (SCM_BIGSIGN (num)) + scm_out_of_range (s_caller, num); + for (l = SCM_NUMDIGS (num); l--;) { - res = SCM_BIGUP (res) + SCM_BDIGITS (num)[l]; - if (res >= old_res) { - old_res = res; - } else { + if (res > SCM_BIGDN(ULONG_MAX)) scm_out_of_range (s_caller, num); - } + res = SCM_BIGUP (res) + SCM_BDIGITS (num)[l]; } return res; } else if (SCM_REALP (num)) {