]> git.lizzy.rs Git - rust.git/commitdiff
Add a test to check that badly written Ord impl do not cause double frees
authorSimon BD <simon@server>
Sat, 6 Oct 2012 18:07:29 +0000 (13:07 -0500)
committerSimon BD <simon@server>
Sat, 6 Oct 2012 18:07:29 +0000 (13:07 -0500)
src/libstd/sort.rs

index f3c2f5ff44660cd7ebb5b8eaa5c3cb006e0fb0ed..7bafb324dad04fc4e4629b218f2db9de12f00f6c 100644 (file)
@@ -1043,6 +1043,27 @@ fn crash_test() {
         tim_sort(arr);
         fail ~"Guarantee the fail";
     }
+
+    struct DVal { val: ~uint }
+    impl DVal: Ord {
+        pure fn lt(other: &DVal) -> bool { true }
+        pure fn le(other: &DVal) -> bool { true }
+        pure fn gt(other: &DVal) -> bool { true }
+        pure fn ge(other: &DVal) -> bool { true }
+    }
+
+    #[test]
+    #[should_fail]
+    fn test_bad_Ord_impl() {
+        let rng = rand::Rng();
+        let mut arr = do vec::from_fn(500) |_i| {
+            let randVal = rng.gen_uint();
+            DVal { val: ~randVal }
+        };
+
+        tim_sort(arr);
+        fail ~"Guarantee the fail";
+    }
 }
 
 /*fn f<T: Ord>(array: &[mut T]) { array[0] <-> array[0] }