diff --git a/src/libcore/str.rs b/src/libcore/str.rs index b3f58ce2558ff..0e5f956d866f1 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -667,7 +667,7 @@ pure fn eq_slice(a: &str, b: &str) -> bool { unsafe { libc::memcmp(ap as *libc::c_void, bp as *libc::c_void, - alen as libc::size_t) == 0 + (alen - 1) as libc::size_t) == 0 } } } @@ -2225,6 +2225,13 @@ mod tests { assert (!eq(&~"foo", &~"bar")); } + #[test] + fn test_eq_slice() { + assert (eq_slice(view("foobar", 0, 3), "foo")); + assert (eq_slice(view("barfoo", 3, 6), "foo")); + assert (!eq_slice("foo1", "foo2")); + } + #[test] fn test_le() { assert (le(&"", &""));