From 383f5bdfee5830c66cd273f5b4ee9be47d093b31 Mon Sep 17 00:00:00 2001 From: Torsten Scheck Date: Mon, 3 Jul 2017 18:04:37 +0200 Subject: [PATCH] Fix potential invalid memory reference. --- solutions/src/list.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/solutions/src/list.rs b/solutions/src/list.rs index 3206982..c7ae6ad 100644 --- a/solutions/src/list.rs +++ b/solutions/src/list.rs @@ -53,6 +53,8 @@ impl LinkedList { if new_last.is_null() { // The list is now empty. self.first = new_last; + } else { + unsafe { (*new_last).next = ptr::null_mut() }; } let last = unsafe { raw_into_box(last) } ; Some(last.data) @@ -86,6 +88,8 @@ impl LinkedList { if new_first.is_null() { // The list is now empty. self.last = new_first; + } else { + unsafe { (*new_first).prev = ptr::null_mut() }; } let first = unsafe { raw_into_box(first) } ; Some(first.data) -- 2.30.2