adding bound checks for raw::memcpy and memmove

This commit is contained in:
asdf 2013-01-05 05:52:37 -05:00 committed by Graydon Hoare
parent 2d9b1fee8f
commit 4096c9f25f

View File

@ -1960,6 +1960,9 @@ pub mod raw {
* may overlap.
*/
pub unsafe fn memcpy<T>(dst: &[mut T], src: &[const T], count: uint) {
assert dst.len() >= count;
assert src.len() >= count;
do as_mut_buf(dst) |p_dst, _len_dst| {
do as_const_buf(src) |p_src, _len_src| {
ptr::memcpy(p_dst, p_src, count)
@ -1974,6 +1977,9 @@ pub mod raw {
* may overlap.
*/
pub unsafe fn memmove<T>(dst: &[mut T], src: &[const T], count: uint) {
assert dst.len() >= count;
assert src.len() >= count;
do as_mut_buf(dst) |p_dst, _len_dst| {
do as_const_buf(src) |p_src, _len_src| {
ptr::memmove(p_dst, p_src, count)
@ -3730,6 +3736,15 @@ mod tests {
fail
}
}
#[test]
#[should_fail]
fn test_memcpy_oob() unsafe {
let a = [mut 1, 2, 3, 4];
let b = [1, 2, 3, 4, 5];
raw::memcpy(a, b, 5);
}
}
// Local Variables: