Skip to content

Commit 9b57391

Browse files
committed
Fix heap corruption in Floyd's algorithm tests
1 parent 44d02d7 commit 9b57391

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/data_structures/floyds_algorithm.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,5 +91,12 @@ mod tests {
9191

9292
assert!(has_cycle(&linked_list));
9393
assert_eq!(detect_cycle(&linked_list), Some(3));
94+
95+
// Break the cycle before the list is dropped
96+
unsafe {
97+
if let Some(mut tail) = linked_list.tail {
98+
tail.as_mut().next = None;
99+
}
100+
}
94101
}
95102
}

0 commit comments

Comments
 (0)