summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-string-ext/src
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2013-08-26 04:17:20 -0700
committerYukihiro "Matz" Matsumoto <[email protected]>2013-08-26 04:17:20 -0700
commit91b878e5dfa671b63c26019962736dda1a58f9fc (patch)
tree1045a9cfeb500bb58cea6a787c1bf7efe88a630e /mrbgems/mruby-string-ext/src
parentb11ae3fddbda288effeaa74c6fe5e6880f028af0 (diff)
parentd682be9d328227aff3597ddb40cb21ecb5816f1d (diff)
downloadmruby-91b878e5dfa671b63c26019962736dda1a58f9fc.tar.gz
mruby-91b878e5dfa671b63c26019962736dda1a58f9fc.zip
Merge pull request #1485 from fjmilens3/string_end_with
Bug in String#end_with? resulting from incorrect length determination
Diffstat (limited to 'mrbgems/mruby-string-ext/src')
-rw-r--r--mrbgems/mruby-string-ext/src/string.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/mrbgems/mruby-string-ext/src/string.c b/mrbgems/mruby-string-ext/src/string.c
index 33ed3095b..7bb6254ce 100644
--- a/mrbgems/mruby-string-ext/src/string.c
+++ b/mrbgems/mruby-string-ext/src/string.c
@@ -143,15 +143,16 @@ mrb_str_end_with(mrb_state *mrb, mrb_value self)
mrb_get_args(mrb, "*", &argv, &argc);
for (i = 0; i < argc; i++) {
- size_t len_l, len_r, len_cmp;
+ size_t len_l, len_r;
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) {
+ if (memcmp(RSTRING_PTR(self) + (len_l - len_r),
+ RSTRING_PTR(argv[i]),
+ len_r) == 0) {
+ return mrb_true_value();
+ }
+ }
}
return mrb_false_value();
}