* [r6rs] frontier port position rejected with bytevector ports
@ 2011-04-07 7:42 Marco Maggi
0 siblings, 0 replies; 3+ messages in thread
From: Marco Maggi @ 2011-04-07 7:42 UTC (permalink / raw)
To: bug-guile
The following program fails:
#!r6rs
(import (rnrs))
(define port (open-bytevector-input-port '#vu8()))
(set-port-position! port (port-position port))
and the following fails, too:
#!r6rs
(import (rnrs))
(define port (open-bytevector-input-port '#vu8(1 2 3)))
(write (port-position port))(newline)
(get-u8 port)
(write (port-position port))(newline)
(get-u8 port)
(write (port-position port))(newline)
(get-u8 port)
(write (port-position port))(newline)
(set-port-position! port (port-position port))
because of an attempt to set the port position to an invalid
value; but if a position is returned by PORT-POSITION, it
must be possible to SET-PORT-POSITION! to such value. All
the R6RS implementations I tested (but Mosh) accept this.
--
Marco Maggi
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [r6rs] frontier port position rejected with bytevector ports
@ 2011-04-08 2:06 Ian Price
2011-04-11 16:16 ` Andy Wingo
0 siblings, 1 reply; 3+ messages in thread
From: Ian Price @ 2011-04-08 2:06 UTC (permalink / raw)
To: marco.maggi-ipsu; +Cc: bug-guile
[-- Attachment #1: Type: text/plain, Size: 219 bytes --]
Hello,
I'm not too familiar with guile's codebase, but I think I've found the
bug. It's a fencepost error in the SEEK_SET case of bip_seek from
libguile/r6rs-ports.c . I've attached a fix for stable-2.0
Regards,
Ian
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Fix for Marco Maggi --]
[-- Type: text/x-patch, Size: 1908 bytes --]
From c3fd372c573ae1bc9cdf3cb0ef69d6a0592ec020 Mon Sep 17 00:00:00 2001
From: Ian Price <ianprice90@googlemail.com>
Date: Fri, 8 Apr 2011 02:49:20 +0100
Subject: [PATCH] Fix fencepost error in bip_seek
* libguile/r6rs-ports.c (bip_seek): Fix to allow seeking to end of port.
* test-suite/tests/r6rs-ports.test ("bytevector input port can seek to
very end"): Add tests.
---
libguile/r6rs-ports.c | 2 +-
test-suite/tests/r6rs-ports.test | 9 +++++++++
2 files changed, 10 insertions(+), 1 deletions(-)
diff --git a/libguile/r6rs-ports.c b/libguile/r6rs-ports.c
index 1f72415..7473db9 100644
--- a/libguile/r6rs-ports.c
+++ b/libguile/r6rs-ports.c
@@ -136,7 +136,7 @@ bip_seek (SCM port, scm_t_off offset, int whence)
/* Fall through. */
case SEEK_SET:
- if (c_port->read_buf + offset < c_port->read_end)
+ if (c_port->read_buf + offset <= c_port->read_end)
{
c_port->read_pos = c_port->read_buf + offset;
c_result = offset;
diff --git a/test-suite/tests/r6rs-ports.test b/test-suite/tests/r6rs-ports.test
index 70b5853..01d8235 100644
--- a/test-suite/tests/r6rs-ports.test
+++ b/test-suite/tests/r6rs-ports.test
@@ -320,6 +320,15 @@
(u8-list->bytevector
(map char->integer (string->list "Port!")))))))
+ (pass-if "bytevector input port can seek to very end"
+ (let ((empty (open-bytevector-input-port '#vu8()))
+ (not-empty (open-bytevector-input-port '#vu8(1 2 3))))
+ (and (begin (set-port-position! empty (port-position empty))
+ (= 0 (port-position empty)))
+ (begin (get-bytevector-n not-empty 3)
+ (set-port-position! not-empty (port-position not-empty))
+ (= 3 (port-position not-empty))))))
+
(pass-if-exception "make-custom-binary-input-port [wrong-num-args]"
exception:wrong-num-args
--
1.7.3.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [r6rs] frontier port position rejected with bytevector ports
2011-04-08 2:06 Ian Price
@ 2011-04-11 16:16 ` Andy Wingo
0 siblings, 0 replies; 3+ messages in thread
From: Andy Wingo @ 2011-04-11 16:16 UTC (permalink / raw)
To: Ian Price; +Cc: bug-guile
On Fri 08 Apr 2011 04:06, Ian Price <ianprice90@googlemail.com> writes:
> I'm not too familiar with guile's codebase, but I think I've found the
> bug. It's a fencepost error in the SEEK_SET case of bip_seek from
> libguile/r6rs-ports.c . I've attached a fix for stable-2.0
Yes, that does sound right. Good catch. Applied, and thanks for the
test.
Andy
--
http://wingolog.org/
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-04-11 16:16 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-04-07 7:42 [r6rs] frontier port position rejected with bytevector ports Marco Maggi
-- strict thread matches above, loose matches on Subject: below --
2011-04-08 2:06 Ian Price
2011-04-11 16:16 ` 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).