chopped_length should return early for empty strings
The current implementation only tries to check if the beginning of the string isn't coming after its end (I'm not even really sure if that's possible actually, is there case where RSTRING_LEN returns a negative number?).
In any case, here's the change (and the patch's attached to the ticket):
diff --git a/string.c b/string.c index 5696057..592fb2c 100644 --- a/string.c +++ b/string.c @@ -7138,7 +7138,7 @@ chopped_length(VALUE str) beg = RSTRING_PTR(str); end = beg + RSTRING_LEN(str); - if (beg > end) return 0; + if (beg >= end) return 0; p = rb_enc_prev_char(beg, end, end, enc);
I ran the test and things seem to look OK :-) I hope I'm not overlooking something.