projects
/
rust-101.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
d20f370
)
Fix potential invalid memory reference.
author
Torsten Scheck
<torsten.scheck@gmx.de>
Mon, 3 Jul 2017 16:04:37 +0000
(18:04 +0200)
committer
Torsten Scheck
<torsten.scheck@gmx.de>
Mon, 3 Jul 2017 16:04:37 +0000
(18:04 +0200)
solutions/src/list.rs
patch
|
blob
|
history
diff --git
a/solutions/src/list.rs
b/solutions/src/list.rs
index 3206982e9de23650084d534107467474105dfad0..c7ae6ad2565651a2628536cce710d2e3cdb1c2c4 100644
(file)
--- a/
solutions/src/list.rs
+++ b/
solutions/src/list.rs
@@
-53,6
+53,8
@@
impl<T> LinkedList<T> {
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<T> LinkedList<T> {
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)