From 92cbda2c05ba49c82c509a536d0a33e9518894ce Mon Sep 17 00:00:00 2001 From: chriseth Date: Wed, 5 Apr 2023 16:51:01 +0200 Subject: [PATCH] Assert degree is large enough. --- src/parser/ast.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/parser/ast.rs b/src/parser/ast.rs index 23e178b2a..501b6f1bb 100644 --- a/src/parser/ast.rs +++ b/src/parser/ast.rs @@ -127,12 +127,17 @@ impl ArrayExpression { impl ArrayExpression { /// solve for `*` pub fn solve(&self, degree: DegreeType) -> Option { + assert!(degree > 0, "Degree cannot be zero."); // the length of this expression is `a + b*x` let (a, b) = self.len(); // it must match `degree`, and we solve for `x` if b == 0 { None } else { + assert!( + a <= degree, + "Array literal is too large ({a}) for degree ({degree})." + ); assert_eq!((degree - a) % b, 0, "Cannot find a suitable value for `*`"); Some((degree - a) / b) }