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>
This commit is contained in:
bors[bot] 2021-06-07 21:28:02 +00:00 committed by GitHub
commit 9bea30b5a8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -269,6 +269,11 @@ where
let len = N::U16; let len = N::U16;
let mut free = 0; let mut free = 0;
if len == 0 {
list.free = LinkedIndex::none();
return list;
}
// Initialize indexes // Initialize indexes
while free < len - 1 { while free < len - 1 {
unsafe { unsafe {
@ -557,6 +562,14 @@ mod tests {
assert!(ll.is_empty()) assert!(ll.is_empty())
} }
#[test]
fn test_zero_size() {
let ll: LinkedList<u32, Max, U0> = LinkedList::new();
assert!(ll.is_empty());
assert!(ll.is_full());
}
#[test] #[test]
fn test_rejected_push() { fn test_rejected_push() {
let mut ll: LinkedList<u32, Max, U3> = LinkedList::new(); let mut ll: LinkedList<u32, Max, U3> = LinkedList::new();