mirror of
https://github.com/rtic-rs/rtic.git
synced 2024-11-23 20:22:51 +01:00
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>
This commit is contained in:
commit
9bea30b5a8
1 changed files with 13 additions and 0 deletions
|
@ -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();
|
||||||
|
|
Loading…
Reference in a new issue