diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-01-14 15:07:49 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-01-14 15:07:49 +0000 |
commit | c459a29b9e03ac2a3fa089f8c079a580407172a7 (patch) | |
tree | 719f2b4bb8b2f330a39ea68e8dfd20af13b103bd /io.c | |
parent | 0e04bd210f6b0b2efcfcc74c0dd16df8683dadf0 (diff) | |
download | ruby-c459a29b9e03ac2a3fa089f8c079a580407172a7.tar.gz ruby-c459a29b9e03ac2a3fa089f8c079a580407172a7.tar.xz ruby-c459a29b9e03ac2a3fa089f8c079a580407172a7.zip |
* io.c (appendline): specifying limit should not generate broken
byte sequence. strings should be rounded. [ruby-dev:33088]
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@15051 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r-- | io.c | 12 |
1 files changed, 12 insertions, 0 deletions
@@ -1712,6 +1712,18 @@ appendline(rb_io_t *fptr, int delim, const char *rsptr, int rslen, VALUE *strp, if (c != EOF) { RSTRING_PTR(str)[last++] = c; } + if (limit > 0 && limit == pending) { + char *p = fptr->rbuf+fptr->rbuf_off; + char *pp = p + limit; + char *pl = rb_enc_left_char_head(p, pp, io_read_encoding(fptr)); + + if (pl < pp) { + int diff = pp - pl; + pending -= diff; + limit = pending; + rb_str_set_len(str, RSTRING_LEN(str)-diff); + } + } read_buffered_data(RSTRING_PTR(str) + last, pending, fptr); /* must not fail */ limit -= pending; *lp = limit; |