summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-01-03 15:40:45 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-01-03 15:40:45 +0000
commit1aaf8b171373f6862fa8c523923b98ef6feb1c65 (patch)
tree80cb96397af780182e3b341c92e1b42741ab8f69
parentf905704727b20865f71a10fbc34ed032346a7f93 (diff)
* io.c (io_ungetc): move data in buffer if it is required to store the
argument. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14873 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-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);