From 588d673ad087012d77637ab2623d8c13706187e6 Mon Sep 17 00:00:00 2001 From: tali Date: Sun, 16 Apr 2023 03:46:49 -0400 Subject: [PATCH] panic if queue is too big --- mino/src/queue.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mino/src/queue.rs b/mino/src/queue.rs index 5850b88..a2d64c8 100644 --- a/mino/src/queue.rs +++ b/mino/src/queue.rs @@ -12,6 +12,10 @@ pub struct Queue<'a, T: Copy> { impl<'a, T: Copy> Queue<'a, T> { /// Constructs a new queue. pub const fn new(mut hold: Option, mut next: &'a [T]) -> Self { + if next.len() + 1 > u16::MAX as usize { + panic!("too many elements in queue"); + } + // SIGH. so `hold.is_none()` is not valid in `const fn`, for some obscure reason. #[allow(clippy::redundant_pattern_matching)] if let None = hold {