Project

General

Profile

Actions

Bug #11391

closed

chopped_length should return early for empty strings

Added by cesario (Franck Verrot) over 8 years ago. Updated about 5 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.3.0dev (2015-07-22 trunk 51338) [x86_64-darwin14]
Backport:
[ruby-core:70096]

Description

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.
Thanks!


Files

Actions #1

Updated by nobu (Nobuyoshi Nakada) about 5 years ago

  • Status changed from Open to Closed

Applied in changeset trunk|r67018.


  • string.c (chopped_length): early return for empty strings

[Bug #11391]

From: Franck Verrot

Actions

Also available in: Atom PDF

Like0
Like0