unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
* Error in vector-move-left! & vector-move-right!
@ 2011-02-14  4:21 Ian Price
  2011-02-14 19:23 ` Andy Wingo
  0 siblings, 1 reply; 2+ messages in thread
From: Ian Price @ 2011-02-14  4:21 UTC (permalink / raw)
  To: bug-guile

[-- Attachment #1: Type: text/plain, Size: 1912 bytes --]

Hi all,

I was trying to copy a vector slice into another destructively using
vector-move-(left!|right!) and came across a bug. If you try to fill
the whole of the destination vector, you will get an error. This
happens with both vector-move-left! and vector-move-right!, and it
does not matter if the source vector and the destination vector are
distinct.

$ guile
GNU Guile 1.9.15.76-eb7a1
Copyright (C) 1995-2011 Free Software Foundation, Inc.

Guile comes with ABSOLUTELY NO WARRANTY; for details type `,show w'.
This program is free software, and you are welcome to redistribute it
under certain conditions; type `,show c' for details.

Enter `,help' for help.
scheme@(guile-user)> (define vec1 (make-vector 4 #f))
scheme@(guile-user)> (define vec2 (make-vector 4 #t))
scheme@(guile-user)> (vector-move-left! vec1 0 4 vec2 0)
ERROR: In procedure vector-move-left!:
ERROR: In procedure vector-move-left!: Argument 3 out of range: 4

Entering a new prompt.  Type `,bt' for a backtrace or `,q' to continue.
scheme@(guile-user) [1]> ,q
scheme@(guile-user)> (define vec1 (make-vector 6 #f))
scheme@(guile-user)> (vector-move-right! vec1 1 5 vec2 0)
ERROR: In procedure vector-move-right!:
ERROR: In procedure vector-move-right!: Argument 3 out of range: 5

Entering a new prompt.  Type `,bt' for a backtrace or `,q' to continue.
scheme@(guile-user) [1]> ,q
scheme@(guile-user)> (vector-move-left! vec1 0 6 vec1 0)
ERROR: In procedure vector-move-left!:
ERROR: In procedure vector-move-left!: Argument 3 out of range: 6

Entering a new prompt.  Type `,bt' for a backtrace or `,q' to continue.
scheme@(guile-user) [1]> ,q


The culprit is an assertion common to both definitions in
libguile/vectors.c that only allows you to move the values if the
length of the vector to be moved is less than the length of the vector
you are moving it to.

Trivial patch is attached.

Looking forward to the release of 2.0,

Ian

[-- Attachment #2: 0001-libguile-vectors.c-Fix-edge-case-in-s_scm_vector_mov.patch --]
[-- Type: application/octet-stream, Size: 1316 bytes --]

From 81c9cc87ae1033e0612457d677c3348cafb440fe Mon Sep 17 00:00:00 2001
From: Ian Price <ianprice90@googlemail.com>
Date: Mon, 14 Feb 2011 03:44:31 +0000
Subject: [PATCH] * libguile/vectors.c : Fix edge case in s_scm_vector_move_right_x and
   s_scm_vector_move_left_x

---
 libguile/vectors.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/libguile/vectors.c b/libguile/vectors.c
index f9b4fc2..2ab5b78 100644
--- a/libguile/vectors.c
+++ b/libguile/vectors.c
@@ -533,7 +533,7 @@ 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);
-  SCM_ASSERT_RANGE (SCM_ARG3, end1, (e-i) < len2);
+  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));
   
@@ -573,7 +573,7 @@ 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);
-  SCM_ASSERT_RANGE (SCM_ARG3, end1, (e-i) < len2);
+  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));
   
-- 
1.7.3.4


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: Error in vector-move-left! & vector-move-right!
  2011-02-14  4:21 Error in vector-move-left! & vector-move-right! Ian Price
@ 2011-02-14 19:23 ` Andy Wingo
  0 siblings, 0 replies; 2+ messages in thread
From: Andy Wingo @ 2011-02-14 19:23 UTC (permalink / raw)
  To: Ian Price; +Cc: bug-guile

On Mon 14 Feb 2011 05:21, Ian Price <ianprice90@googlemail.com> writes:

> The culprit is an assertion common to both definitions in
> libguile/vectors.c that only allows you to move the values if the
> length of the vector to be moved is less than the length of the vector
> you are moving it to.
>
> Trivial patch is attached.

Applied.  Thanks!

Andy
-- 
http://wingolog.org/



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-02-14 19:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-02-14  4:21 Error in vector-move-left! & vector-move-right! Ian Price
2011-02-14 19:23 ` Andy Wingo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).