* io.c (io_ungetc): avoid buffer relocation, which might cause

serious problem under concurrent situation.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14439 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2007-12-21 16:54:25 +00:00
parent b82a05989e
commit 2bed2cdc7f
2 changed files with 6 additions and 10 deletions

View File

@ -1,3 +1,8 @@
Sat Dec 22 01:52:11 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
* io.c (io_ungetc): avoid buffer relocation, which might cause
serious problem under concurrent situation.
Sat Dec 22 01:35:41 2007 Tanaka Akira <akr@fsij.org>
* re.c (ARG_ENCODING_NONE): defined for /.../n option.

11
io.c
View File

@ -310,16 +310,7 @@ io_ungetc(VALUE str, rb_io_t *fptr)
fptr->rbuf = ALLOC_N(char, fptr->rbuf_capa);
}
if (fptr->rbuf_off < len) {
int capa = fptr->rbuf_len + len;
char *buf = ALLOC_N(char, capa);
if (fptr->rbuf_len) {
MEMMOVE(buf+len, fptr->rbuf+fptr->rbuf_off, char, fptr->rbuf_len);
}
fptr->rbuf_capa = capa;
fptr->rbuf_off = len;
free(fptr->rbuf);
fptr->rbuf = buf;
rb_raise(rb_eIOError, "ungetc failed");
}
fptr->rbuf_off-=len;
fptr->rbuf_len+=len;