1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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
This commit is contained in:
akr 2008-01-03 15:40:45 +00:00
parent f905704727
commit 1aaf8b1713
2 changed files with 12 additions and 1 deletions

View file

@ -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.

8
io.c
View file

@ -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);