diff options
author | Mark H Weaver <mhw@netris.org> | 2014-11-12 00:40:47 -0500 |
---|---|---|
committer | Mark H Weaver <mhw@netris.org> | 2014-11-12 00:50:38 -0500 |
commit | ae6f77ddfaf8e752589d9050c9e517cb1c52cbf0 (patch) | |
tree | 2b5ce44f15e5c494a0b5f1c0191295b75a26d99c | |
parent | 81d2c84674f03f9028f26474ab19d3d3f353881a (diff) | |
download | guile-ae6f77ddfaf8e752589d9050c9e517cb1c52cbf0.tar.gz |
Fix bytevector-fill! to accept fill arguments greater than 127.
Fixes <http://bugs.gnu.org/19027>.
* libguile/bytevectors.c (scm_bytevector_fill_x): Accept fill arguments
between -128 and 255.
* test-suite/tests/bytevectors.test ("2.2 General Operations"): Add
tests.
-rw-r--r-- | libguile/bytevectors.c | 7 | ||||
-rw-r--r-- | test-suite/tests/bytevectors.test | 15 |
2 files changed, 21 insertions, 1 deletions
diff --git a/libguile/bytevectors.c b/libguile/bytevectors.c index 9f6b6abf3..8f698d5ba 100644 --- a/libguile/bytevectors.c +++ b/libguile/bytevectors.c @@ -537,9 +537,14 @@ SCM_DEFINE (scm_bytevector_fill_x, "bytevector-fill!", 2, 0, 0, { size_t c_len, i; scm_t_uint8 *c_bv, c_fill; + int value; SCM_VALIDATE_BYTEVECTOR (1, bv); - c_fill = scm_to_int8 (fill); + + value = scm_to_int (fill); + if (SCM_UNLIKELY ((value < -128) || (value > 255))) + scm_out_of_range (FUNC_NAME, fill); + c_fill = (scm_t_uint8) value; c_len = SCM_BYTEVECTOR_LENGTH (bv); c_bv = (scm_t_uint8 *) SCM_BYTEVECTOR_CONTENTS (bv); diff --git a/test-suite/tests/bytevectors.test b/test-suite/tests/bytevectors.test index 8abda4a8e..5b5adb367 100644 --- a/test-suite/tests/bytevectors.test +++ b/test-suite/tests/bytevectors.test @@ -46,6 +46,21 @@ (not (bytevector=? (make-bytevector 20 7) (make-bytevector 20 0))))) + ;; This failed prior to Guile 2.0.12. + ;; See <http://bugs.gnu.org/19027>. + (pass-if-equal "bytevector-fill! with fill 255" + #vu8(255 255 255 255) + (let ((bv (make-bytevector 4))) + (bytevector-fill! bv 255) + bv)) + + ;; This is a Guile-specific extension. + (pass-if-equal "bytevector-fill! with fill -128" + #vu8(128 128 128 128) + (let ((bv (make-bytevector 4))) + (bytevector-fill! bv -128) + bv)) + (pass-if "bytevector-copy! overlapping" ;; See <http://debbugs.gnu.org/10070>. (let ((b (u8-list->bytevector '(1 2 3 4 5 6 7 8)))) |