mozilla/rust — pull request #3364 by apasel422 (2012-09-03 17:21:52+00:00)
Title: fix str::eq_slice off-by-one error

The new `memcmp`-based implementation of `str::eq_slice` (54a8d69c4feb878e0367cc55772c04ee2d59c8a5) uses `str::as_buf`, which, according to its documentation, passes one more than the real length of the string in order to facilitate null-terminator checks. `eq_slice` doesn't take this into account, and compares the next byte beyond the ends of the slices it is given. For full strings, this is the null terminator, but for slices in the middle of a string, this is whatever the next UTF-8 byte is.

Therefore, code like `assert str::view("foobar", 0, 3) == "foo";` fails.

This fix simply subtracts one from the length yielded by `as_buf` in order to compensate for this.