@@ -1512,6 +1512,13 @@ fn test_copy_within() {
15121512 let mut bytes = * b"Hello, World!" ;
15131513 bytes. copy_within ( .., 0 ) ;
15141514 assert_eq ! ( & bytes, b"Hello, World!" ) ;
1515+
1516+ // Ensure that copying at the end of slice won't cause UB.
1517+ let mut bytes = * b"Hello, World!" ;
1518+ bytes. copy_within ( 13 ..13 , 5 ) ;
1519+ assert_eq ! ( & bytes, b"Hello, World!" ) ;
1520+ bytes. copy_within ( 5 ..5 , 13 ) ;
1521+ assert_eq ! ( & bytes, b"Hello, World!" ) ;
15151522}
15161523
15171524#[ test]
@@ -1536,6 +1543,13 @@ fn test_copy_within_panics_src_inverted() {
15361543 // 2 is greater than 1, so this range is invalid.
15371544 bytes. copy_within ( 2 ..1 , 0 ) ;
15381545}
1546+ #[ test]
1547+ #[ should_panic( expected = "attempted to index slice up to maximum usize" ) ]
1548+ fn test_copy_within_panics_src_out_of_bounds ( ) {
1549+ let mut bytes = * b"Hello, World!" ;
1550+ // 2 is greater than 1, so this range is invalid.
1551+ bytes. copy_within ( usize:: max_value ( ) ..=usize:: max_value ( ) , 0 ) ;
1552+ }
15391553
15401554#[ test]
15411555fn test_is_sorted ( ) {
0 commit comments