Fix list::remove when trying to remove first element of the list (SIGSEGV)
This commit is contained in:
parent
24be35547e
commit
8b3a3bebe7
@ -141,6 +141,8 @@ impl ThreadManager {
|
||||
let old_status = machine.interrupt.set_status(InterruptStatus::InterruptOff);
|
||||
self.g_thread_to_be_destroyed = Option::Some(Rc::clone(&thread));
|
||||
self.g_alive.remove(Rc::clone(&thread));
|
||||
#[cfg(debug_assertions)]
|
||||
println!("Sleeping thread {}", thread.borrow().get_name());
|
||||
// g_objets_addrs->removeObject(self.thread) // a ajouté plus tard
|
||||
self.thread_sleep(machine, Rc::clone(&thread));
|
||||
machine.interrupt.set_status(old_status);
|
||||
|
@ -113,8 +113,12 @@ impl<T: PartialEq> List<T> {
|
||||
let mut current: *mut Node<T> = self.head;
|
||||
let mut previous: *mut Node<T> = ptr::null_mut();
|
||||
while !current.is_null() {
|
||||
if (*current).elem == item {
|
||||
if (&*current).elem == item {
|
||||
if !previous.is_null() {
|
||||
(*previous).next = (*current).next;
|
||||
} else {
|
||||
self.head = (*current).next;
|
||||
}
|
||||
drop(Box::from_raw(current).elem);
|
||||
return true;
|
||||
} else {
|
||||
@ -320,6 +324,22 @@ mod test {
|
||||
assert_eq!(list.peek(), Option::None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn remove_test2() {
|
||||
let mut list = List::default();
|
||||
assert_eq!(list.peek(), None);
|
||||
list.push(1);
|
||||
list.push(2);
|
||||
list.push(3);
|
||||
|
||||
assert_eq!(list.contains(&1), true);
|
||||
list.remove(1);
|
||||
assert_eq!(list.contains(&1), false);
|
||||
assert_eq!(list.pop(), Option::Some(2));
|
||||
assert_eq!(list.pop(), Option::Some(3));
|
||||
assert_eq!(list.peek(), Option::None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn miri_test() {
|
||||
let mut list = List::default();
|
||||
|
Loading…
Reference in New Issue
Block a user