mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-31 09:20:23 +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:
parent
62e63ba927
commit
5345cf7cae
1 changed files with 5 additions and 6 deletions
|
@ -4472,16 +4472,15 @@ scm_num2ulong (SCM num, char *pos, const char *s_caller)
|
||||||
}
|
}
|
||||||
} else if (SCM_BIGP (num)) {
|
} else if (SCM_BIGP (num)) {
|
||||||
unsigned long int res = 0;
|
unsigned long int res = 0;
|
||||||
unsigned long int old_res = 0;
|
|
||||||
scm_sizet l;
|
scm_sizet l;
|
||||||
|
|
||||||
|
if (SCM_BIGSIGN (num))
|
||||||
|
scm_out_of_range (s_caller, num);
|
||||||
|
|
||||||
for (l = SCM_NUMDIGS (num); l--;) {
|
for (l = SCM_NUMDIGS (num); l--;) {
|
||||||
res = SCM_BIGUP (res) + SCM_BDIGITS (num)[l];
|
if (res > SCM_BIGDN(ULONG_MAX))
|
||||||
if (res >= old_res) {
|
|
||||||
old_res = res;
|
|
||||||
} else {
|
|
||||||
scm_out_of_range (s_caller, num);
|
scm_out_of_range (s_caller, num);
|
||||||
}
|
res = SCM_BIGUP (res) + SCM_BDIGITS (num)[l];
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
} else if (SCM_REALP (num)) {
|
} else if (SCM_REALP (num)) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue