mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-19 11:10:25 +02:00
Fix size measurement in bytevector_large_set
* libguile/bytevectors.c (bytevector_large_set): Fix computation of value size in words. * test-suite/tests/bytevectors.test: Add test. Thanks to Ben Rocer <fleabyte@mail.com> for the bug report and fix.
This commit is contained in:
parent
0a3ea0586d
commit
b77642dff2
2 changed files with 9 additions and 4 deletions
|
@ -857,10 +857,11 @@ bytevector_large_set (char *c_bv, size_t c_size, int signed_p,
|
||||||
memset (c_bv, 0, c_size);
|
memset (c_bv, 0, c_size);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
size_t word_count, value_size;
|
size_t word_count, value_words;
|
||||||
|
|
||||||
value_size = (mpz_sizeinbase (c_mpz, 2) + (8 * c_size)) / (8 * c_size);
|
value_words = ((mpz_sizeinbase (c_mpz, 2) + (8 * c_size) - 1) /
|
||||||
if (SCM_UNLIKELY (value_size > c_size))
|
(8 * c_size));
|
||||||
|
if (SCM_UNLIKELY (value_words > 1))
|
||||||
{
|
{
|
||||||
err = -2;
|
err = -2;
|
||||||
goto finish;
|
goto finish;
|
||||||
|
|
|
@ -345,7 +345,11 @@
|
||||||
(let ((b (make-bytevector 8)))
|
(let ((b (make-bytevector 8)))
|
||||||
(bytevector-s64-set! b 0 -1 (endianness big))
|
(bytevector-s64-set! b 0 -1 (endianness big))
|
||||||
(bytevector-u64-set! b 0 0 (endianness big))
|
(bytevector-u64-set! b 0 0 (endianness big))
|
||||||
(= 0 (bytevector-u64-ref b 0 (endianness big))))))
|
(= 0 (bytevector-u64-ref b 0 (endianness big)))))
|
||||||
|
|
||||||
|
(pass-if-exception "bignum out of range"
|
||||||
|
exception:out-of-range
|
||||||
|
(bytevector-u64-set! (make-bytevector 8) 0 (expt 2 64) (endianness big))))
|
||||||
|
|
||||||
|
|
||||||
(with-test-prefix/c&e "2.8 Operations on IEEE-754 Representations"
|
(with-test-prefix/c&e "2.8 Operations on IEEE-754 Representations"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue