summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2021-10-08 14:08:03 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2021-10-08 14:08:03 +0900
commit78ff9b719c236b56956d446053256f8e30edf0c3 (patch)
tree6b0b5e9339bc22a1f09708909dae1c24b505dc9f /string.c
parentd0268c5ec20784cf5ed42caf43b076846ae6255a (diff)
Add tests for the edge caces of `String#end_with?`
Also, check if a suffix is empty, to guarantee the assumption of `onigenc_get_left_adjust_char_head` that `*s` is always accessible, even in the case of `SHARABLE_MIDDLE_SUBSTRING`.
Diffstat (limited to 'string.c')
-rw-r--r--string.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/string.c b/string.c
index 7890e6cc88..13079251d4 100644
--- a/string.c
+++ b/string.c
@@ -10237,12 +10237,14 @@ rb_str_end_with(int argc, VALUE *argv, VALUE str)
for (i=0; i<argc; i++) {
VALUE tmp = argv[i];
+ long slen, tlen;
StringValue(tmp);
enc = rb_enc_check(str, tmp);
- if (RSTRING_LEN(str) < RSTRING_LEN(tmp)) continue;
+ if ((tlen = RSTRING_LEN(tmp)) == 0) return Qtrue;
+ if ((slen = RSTRING_LEN(str)) < tlen) continue;
p = RSTRING_PTR(str);
- e = p + RSTRING_LEN(str);
- s = e - RSTRING_LEN(tmp);
+ e = p + slen;
+ s = e - tlen;
if (rb_enc_left_char_head(p, s, e, enc) != s)
continue;
if (memcmp(s, RSTRING_PTR(tmp), RSTRING_LEN(tmp)) == 0)