summaryrefslogtreecommitdiff
path: root/ext/stringio/stringio.c
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2022-05-26 15:22:28 -0700
committergit <svn-admin@ruby-lang.org>2022-05-30 12:55:47 +0900
commit1f82269f4e1bf037e3e5504c6071b905f26fec6f (patch)
treec83f464c070685629e901a9a0e1d702eb0765853 /ext/stringio/stringio.c
parentbb6357cddd5af2c244348e96388a10f7cc6f25b4 (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.c5
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;
}
}