1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-29 08:20:20 +02:00

* numbers.c (scm_num2ulong): Check that a bignum is positive

before looking at the magnitude.  Correctly check for overflow
during conversion.
This commit is contained in:
Marius Vollmer 2001-03-15 19:21:51 +00:00
parent 62e63ba927
commit 5345cf7cae

View file

@ -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)) {