Issue #11391 has been reported by Franck Verrot.

----------------------------------------
Bug #11391: chopped_length should return early for empty strings
https://bugs.ruby-lang.org/issues/11391

* Author: Franck Verrot
* Status: Open
* Priority: Normal
* Assignee: 
* ruby -v: ruby 2.3.0dev (2015-07-22 trunk 51338) [x86_64-darwin14]
* Backport: 
----------------------------------------
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
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.
Thanks!

---Files--------------------------------
0001-string.c-chopped_length-early-return-for-empty-strin.patch (720 Bytes)


-- 
https://bugs.ruby-lang.org/