Project

General

Profile

Bug #11391

chopped_length should return early for empty strings

Added by cesario (Franck Verrot) about 4 years ago. Updated 7 months ago.

Status:
Closed
Priority:
Normal
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

Associated revisions

Revision fb84b86b
Added by nobu (Nobuyoshi Nakada) 7 months ago

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

[Bug #11391]

From: Franck Verrot franck@verrot.fr

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67018 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 67018
Added by nobu (Nobuyoshi Nakada) 7 months ago

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

[Bug #11391]

From: Franck Verrot franck@verrot.fr

History

#1

Updated by nobu (Nobuyoshi Nakada) 7 months 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 franck@verrot.fr

Also available in: Atom PDF