summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--io.c8
2 files changed, 12 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 877f8e7..54ec3c6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Fri Jan 4 00:20:47 2008 Tanaka Akira <akr@fsij.org>
+
+ * io.c (io_ungetc): move data in buffer if it is required to store the
+ argument.
+
Thu Jan 3 21:56:07 2008 Tanaka Akira <akr@fsij.org>
* include/ruby/ruby.h (st_strcasecmp): declared for STRCASECMP.
diff --git a/io.c b/io.c
index 8d8bfe1..12ea578 100644
--- a/io.c
+++ b/io.c
@@ -320,9 +320,15 @@ io_ungetc(VALUE str, rb_io_t *fptr)
fptr->rbuf_capa = 8192;
fptr->rbuf = ALLOC_N(char, fptr->rbuf_capa);
}
- if (fptr->rbuf_off < len) {
+ if (fptr->rbuf_capa < len + fptr->rbuf_len) {
rb_raise(rb_eIOError, "ungetc failed");
}
+ if (fptr->rbuf_off < len) {
+ MEMMOVE(fptr->rbuf+fptr->rbuf_capa-fptr->rbuf_len,
+ fptr->rbuf+fptr->rbuf_off,
+ char, fptr->rbuf_len);
+ fptr->rbuf_off = fptr->rbuf_capa-fptr->rbuf_len;
+ }
fptr->rbuf_off-=len;
fptr->rbuf_len+=len;
MEMMOVE(fptr->rbuf+fptr->rbuf_off, RSTRING_PTR(str), char, len);