Fix for string-length-related issue in String#end_with? logic.

This commit is contained in:
Frederick John Milens III
2013-08-22 18:55:07 -05:00
parent d42427870b
commit a0183b394a
+8 -6
View File
@@ -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();
}