summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-string-ext/src
diff options
context:
space:
mode:
authorFrederick John Milens III <[email protected]>2013-08-22 18:55:07 -0500
committerFrederick John Milens III <[email protected]>2013-08-22 18:55:07 -0500
commita0183b394a699224a6451deb9762b8806799aea7 (patch)
tree4723b06543ec59f19965c17f202c78322c5b3f9e /mrbgems/mruby-string-ext/src
parentd42427870b6c558c43f5bcc876e373b7411ef0e9 (diff)
downloadmruby-a0183b394a699224a6451deb9762b8806799aea7.tar.gz
mruby-a0183b394a699224a6451deb9762b8806799aea7.zip
Fix for string-length-related issue in String#end_with? logic.
Diffstat (limited to 'mrbgems/mruby-string-ext/src')
-rw-r--r--mrbgems/mruby-string-ext/src/string.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/mrbgems/mruby-string-ext/src/string.c b/mrbgems/mruby-string-ext/src/string.c
index edebcecbc..e2ba24d1b 100644
--- a/mrbgems/mruby-string-ext/src/string.c
+++ b/mrbgems/mruby-string-ext/src/string.c
@@ -144,12 +144,14 @@ mrb_str_end_with(mrb_state *mrb, mrb_value self)
size_t len_l, len_r, len_cmp;
len_l = RSTRING_LEN(self);
len_r = RSTRING_LEN(argv[i]);
- len_cmp = (len_l > len_r) ? len_r : len_l;
- if (memcmp(RSTRING_PTR(self) + (len_l - len_cmp),
- RSTRING_PTR(argv[i]) + (len_r - len_cmp),
- len_cmp) == 0) {
- return mrb_true_value();
- }
+ if (len_l >= len_r) {
+ len_cmp = (len_l > len_r) ? len_r : len_l;
+ if (memcmp(RSTRING_PTR(self) + (len_l - len_cmp),
+ RSTRING_PTR(argv[i]) + (len_r - len_cmp),
+ len_cmp) == 0) {
+ return mrb_true_value();
+ }
+ }
}
return mrb_false_value();
}