diff options
author | Jeremy Evans <code@jeremyevans.net> | 2022-05-26 15:22:28 -0700 |
---|---|---|
committer | git <svn-admin@ruby-lang.org> | 2022-05-30 12:55:47 +0900 |
commit | 1f82269f4e1bf037e3e5504c6071b905f26fec6f (patch) | |
tree | c83f464c070685629e901a9a0e1d702eb0765853 /ext/stringio/stringio.c | |
parent | bb6357cddd5af2c244348e96388a10f7cc6f25b4 (diff) |
[ruby/stringio] Fix each with multiple character string and chomp
Previously, this could result in an infinite loop. Always update
the e pointer in this case, setting w when chomping so the chomped
data is not included in the output.
Fixes [Bug #18769]
https://github.com/ruby/stringio/commit/4bf64d5130
Diffstat (limited to 'ext/stringio/stringio.c')
-rw-r--r-- | ext/stringio/stringio.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/ext/stringio/stringio.c b/ext/stringio/stringio.c index f452bd0da0..04ca25b0b8 100644 --- a/ext/stringio/stringio.c +++ b/ext/stringio/stringio.c @@ -1181,7 +1181,7 @@ strio_getline(struct getline_arg *arg, struct StringIO *ptr) const char *s, *e, *p; long n, limit = arg->limit; VALUE str = arg->rs; - int w = 0; + long w = 0; rb_encoding *enc = get_enc(ptr); if (ptr->pos >= (n = RSTRING_LEN(ptr->string))) { @@ -1237,7 +1237,8 @@ strio_getline(struct getline_arg *arg, struct StringIO *ptr) if (e - s < 1024) { for (p = s; p + n <= e; ++p) { if (MEMCMP(p, RSTRING_PTR(str), char, n) == 0) { - e = p + (arg->chomp ? 0 : n); + e = p + n; + w = (arg->chomp ? n : 0); break; } } |