[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 04/11: Fix size measurement in bytevector_large_set
From: |
Andy Wingo |
Subject: |
[Guile-commits] 04/11: Fix size measurement in bytevector_large_set |
Date: |
Tue, 21 Jun 2016 16:10:00 +0000 (UTC) |
wingo pushed a commit to branch stable-2.0
in repository guile.
commit b77642dff2127bfc258e31990f27be37800b8bf6
Author: Andy Wingo <address@hidden>
Date: Mon Jun 20 17:11:59 2016 +0200
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 <address@hidden> for the bug report and fix.
---
libguile/bytevectors.c | 7 ++++---
test-suite/tests/bytevectors.test | 6 +++++-
2 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/libguile/bytevectors.c b/libguile/bytevectors.c
index 8f698d5..cb7f294 100644
--- a/libguile/bytevectors.c
+++ b/libguile/bytevectors.c
@@ -857,10 +857,11 @@ bytevector_large_set (char *c_bv, size_t c_size, int
signed_p,
memset (c_bv, 0, c_size);
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);
- if (SCM_UNLIKELY (value_size > c_size))
+ value_words = ((mpz_sizeinbase (c_mpz, 2) + (8 * c_size) - 1) /
+ (8 * c_size));
+ if (SCM_UNLIKELY (value_words > 1))
{
err = -2;
goto finish;
diff --git a/test-suite/tests/bytevectors.test
b/test-suite/tests/bytevectors.test
index 5b5adb3..84ef907 100644
--- a/test-suite/tests/bytevectors.test
+++ b/test-suite/tests/bytevectors.test
@@ -345,7 +345,11 @@
(let ((b (make-bytevector 8)))
(bytevector-s64-set! b 0 -1 (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"
- [Guile-commits] branch stable-2.0 updated (a192c33 -> dde0d17), Andy Wingo, 2016/06/21
- [Guile-commits] 04/11: Fix size measurement in bytevector_large_set,
Andy Wingo <=
- [Guile-commits] 02/11: Add reference to the lack of "non-greedy" variants, Andy Wingo, 2016/06/21
- [Guile-commits] 06/11: Fix SRFI-2 (and-let*) implementation., Andy Wingo, 2016/06/21
- [Guile-commits] 07/11: Add SRFI-2 (and-let*) test suite., Andy Wingo, 2016/06/21
- [Guile-commits] 01/11: Remove link to Emacs' regexp syntax, Andy Wingo, 2016/06/21
- [Guile-commits] 09/11: Detect too-old libunistring at configure-time., Andy Wingo, 2016/06/21
- [Guile-commits] 10/11: Document pretty-print #:max-expr-width, Andy Wingo, 2016/06/21
- [Guile-commits] 11/11: Use source file permissions for compiled files, Andy Wingo, 2016/06/21
- [Guile-commits] 03/11: Fix uri-decode behavior for "+", Andy Wingo, 2016/06/21
- [Guile-commits] 08/11: Update and-let-star.test, Andy Wingo, 2016/06/21
- [Guile-commits] 05/11: Document sigaction + SA_RESTART, Andy Wingo, 2016/06/21