From a2ead65492c1b6872df30880ca73304b1f3c2ab0 Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Thu, 10 Apr 2025 17:17:13 +0200 Subject: [PATCH] Allow parsing strings larger than 2GiB For a reason unknown, even though `pos` is stored as a `long`, the `#pos` and `#pos=` treat it as an `int`, which prevent skeeing into strings larger than 2GiB. --- ext/strscan/strscan.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ext/strscan/strscan.c b/ext/strscan/strscan.c index 2824eeb4d9..5db12f3df7 100644 --- a/ext/strscan/strscan.c +++ b/ext/strscan/strscan.c @@ -524,7 +524,7 @@ strscan_get_pos(VALUE self) struct strscanner *p; GET_SCANNER(self, p); - return INT2FIX(p->curr); + return LONG2NUM(p->curr); } /* @@ -554,7 +554,7 @@ strscan_set_pos(VALUE self, VALUE v) long i; GET_SCANNER(self, p); - i = NUM2INT(v); + i = NUM2LONG(v); if (i < 0) i += S_LEN(p); if (i < 0) rb_raise(rb_eRangeError, "index out of range"); if (i > S_LEN(p)) rb_raise(rb_eRangeError, "index out of range");