diff options
author | 2021-06-07 21:28:02 +0000 | |
---|---|---|
committer | 2021-06-07 21:28:02 +0000 | |
commit | 9bea30b5a8466f1ecef8a72eccb994be8cba22a8 (patch) | |
tree | d9e4d5a690e2b771930b5c938f64a810015cbad8 | |
parent | 3fd3eea9415da568de51f3fbcebc3a38403367a1 (diff) | |
parent | 87c958da3bf9ef4f2b3c1a7efe4f60480be9eeb1 (diff) | |
download | rtic-9bea30b5a8466f1ecef8a72eccb994be8cba22a8.tar.gz rtic-9bea30b5a8466f1ecef8a72eccb994be8cba22a8.tar.zst rtic-9bea30b5a8466f1ecef8a72eccb994be8cba22a8.zip |
Merge #489
489: Allow zero sized LinkedList r=korken89 a=jhillyerd
If one configures a monotonic in alpha4, but doesn't use it, TimerQueue attempts to create a zero-sized LinkedList, which causes an underflow.
This PR allows for zero-sized linked lists.
Co-authored-by: James Hillyerd <james@hillyerd.com>
-rw-r--r-- | src/linked_list.rs | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/linked_list.rs b/src/linked_list.rs index 6a9836ee..9ea4d19f 100644 --- a/src/linked_list.rs +++ b/src/linked_list.rs @@ -269,6 +269,11 @@ where let len = N::U16; let mut free = 0; + if len == 0 { + list.free = LinkedIndex::none(); + return list; + } + // Initialize indexes while free < len - 1 { unsafe { @@ -558,6 +563,14 @@ mod tests { } #[test] + fn test_zero_size() { + let ll: LinkedList<u32, Max, U0> = LinkedList::new(); + + assert!(ll.is_empty()); + assert!(ll.is_full()); + } + + #[test] fn test_rejected_push() { let mut ll: LinkedList<u32, Max, U3> = LinkedList::new(); ll.push(1).unwrap(); |