summaryrefslogtreecommitdiff
path: root/libguile/vectors.c
diff options
context:
space:
mode:
authorAndy Wingo <wingo@pobox.com>2010-08-04 21:48:00 +0200
committerAndy Wingo <wingo@pobox.com>2010-08-04 21:48:00 +0200
commit551b96d294f3b09c37124562e3da64a7bd399666 (patch)
treef5aee2624b5827c2ecc2d056ec63b1272a96a703 /libguile/vectors.c
parentf9560a348e83ec3c494aee0d42b056383392ffca (diff)
downloadguile-551b96d294f3b09c37124562e3da64a7bd399666.tar.gz
fix vector-move-right! and vector-move-left!
* libguile/vectors.c (scm_vector_move_left_x, scm_vector_move_right_x): Fix some bugs reported by Michael Lucy -- both variants would happily write beyond the end, and vector-move-right! didn't increment the counter before copying in the reverse direction. * test-suite/tests/vectors.test ("vector-move-left!"): ("vector-move-right!"): Add tests.
Diffstat (limited to 'libguile/vectors.c')
-rw-r--r--libguile/vectors.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/libguile/vectors.c b/libguile/vectors.c
index 321b49993..f9b4fc2fd 100644
--- a/libguile/vectors.c
+++ b/libguile/vectors.c
@@ -533,7 +533,9 @@ SCM_DEFINE (scm_vector_move_left_x, "vector-move-left!", 5, 0, 0,
i = scm_to_unsigned_integer (start1, 0, len1);
e = scm_to_unsigned_integer (end1, i, len1);
- j = scm_to_unsigned_integer (start2, 0, len2 - (i-e));
+ SCM_ASSERT_RANGE (SCM_ARG3, end1, (e-i) < len2);
+ j = scm_to_unsigned_integer (start2, 0, len2);
+ SCM_ASSERT_RANGE (SCM_ARG5, start2, j <= len2 - (e - i));
i *= inc1;
e *= inc1;
@@ -571,7 +573,11 @@ SCM_DEFINE (scm_vector_move_right_x, "vector-move-right!", 5, 0, 0,
i = scm_to_unsigned_integer (start1, 0, len1);
e = scm_to_unsigned_integer (end1, i, len1);
- j = scm_to_unsigned_integer (start2, 0, len2 - (i-e));
+ SCM_ASSERT_RANGE (SCM_ARG3, end1, (e-i) < len2);
+ j = scm_to_unsigned_integer (start2, 0, len2);
+ SCM_ASSERT_RANGE (SCM_ARG5, start2, j <= len2 - (e - i));
+
+ j += (e - i);
i *= inc1;
e *= inc1;