mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-20 19:50:24 +02:00
Improved error checking in bytevector->uint-list and bytevector->sint-list.
Partially fixes <http://bugs.gnu.org/15100>. Reported by Göran Weinholt <goran@weinholt.se>. * libguile/bytevectors.c (INTEGERS_TO_LIST): Make sure SIZE isn't 0. Allow SIZE to be greater than the bytevector length, for consistency with allowing extra bytes at the end when the bytevector length is non-zero. Use scm_from_size_t instead of scm_from_uint. * test-suite/tests/bytevectors.test: Add tests. Remove a test that checks for an exception when SIZE is greater than the bytevector length.
This commit is contained in:
parent
8d5d0425ce
commit
088cfb7d76
2 changed files with 12 additions and 6 deletions
|
@ -1099,20 +1099,18 @@ SCM_DEFINE (scm_bytevector_sint_set_x, "bytevector-sint-set!", 5, 0, 0,
|
||||||
\
|
\
|
||||||
SCM_VALIDATE_BYTEVECTOR (1, bv); \
|
SCM_VALIDATE_BYTEVECTOR (1, bv); \
|
||||||
SCM_VALIDATE_SYMBOL (2, endianness); \
|
SCM_VALIDATE_SYMBOL (2, endianness); \
|
||||||
c_size = scm_to_uint (size); \
|
c_size = scm_to_unsigned_integer (size, 1, (size_t) -1); \
|
||||||
\
|
\
|
||||||
c_len = SCM_BYTEVECTOR_LENGTH (bv); \
|
c_len = SCM_BYTEVECTOR_LENGTH (bv); \
|
||||||
if (SCM_UNLIKELY (c_len == 0)) \
|
if (SCM_UNLIKELY (c_len < c_size)) \
|
||||||
lst = SCM_EOL; \
|
lst = SCM_EOL; \
|
||||||
else if (SCM_UNLIKELY (c_len < c_size)) \
|
|
||||||
scm_out_of_range (FUNC_NAME, size); \
|
|
||||||
else \
|
else \
|
||||||
{ \
|
{ \
|
||||||
const char *c_bv; \
|
const char *c_bv; \
|
||||||
\
|
\
|
||||||
c_bv = (char *) SCM_BYTEVECTOR_CONTENTS (bv); \
|
c_bv = (char *) SCM_BYTEVECTOR_CONTENTS (bv); \
|
||||||
\
|
\
|
||||||
lst = scm_make_list (scm_from_uint (c_len / c_size), \
|
lst = scm_make_list (scm_from_size_t (c_len / c_size), \
|
||||||
SCM_UNSPECIFIED); \
|
SCM_UNSPECIFIED); \
|
||||||
for (i = 0, pair = lst; \
|
for (i = 0, pair = lst; \
|
||||||
i <= c_len - c_size; \
|
i <= c_len - c_size; \
|
||||||
|
|
|
@ -155,9 +155,17 @@
|
||||||
(let ((b (make-bytevector 0)))
|
(let ((b (make-bytevector 0)))
|
||||||
(null? (bytevector->uint-list b (endianness big) 2))))
|
(null? (bytevector->uint-list b (endianness big) 2))))
|
||||||
|
|
||||||
|
(pass-if "bytevector->sint-list [length < word size]"
|
||||||
|
(let ((b (make-bytevector 1)))
|
||||||
|
(null? (bytevector->sint-list b (endianness big) 2))))
|
||||||
|
|
||||||
(pass-if-exception "bytevector->sint-list [out-of-range]"
|
(pass-if-exception "bytevector->sint-list [out-of-range]"
|
||||||
exception:out-of-range
|
exception:out-of-range
|
||||||
(bytevector->sint-list (make-bytevector 6) (endianness little) 8))
|
(bytevector->sint-list (make-bytevector 6) (endianness little) -1))
|
||||||
|
|
||||||
|
(pass-if-exception "bytevector->uint-list [out-of-range]"
|
||||||
|
exception:out-of-range
|
||||||
|
(bytevector->uint-list (make-bytevector 6) (endianness little) 0))
|
||||||
|
|
||||||
(pass-if "bytevector->sint-list [off-by-one]"
|
(pass-if "bytevector->sint-list [off-by-one]"
|
||||||
(equal? (bytevector->sint-list (make-bytevector 31 #xff)
|
(equal? (bytevector->sint-list (make-bytevector 31 #xff)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue