Skip to content

Commit

Permalink
Fix expression parser on empty expressions (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
Schamper authored May 24, 2024
1 parent cd9572c commit a72aaae
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
3 changes: 3 additions & 0 deletions dissect/cstruct/expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,4 +299,7 @@ def evaluate(self, context: dict[str, int] | None = None) -> int:

self.evaluate_exp()

if len(self.queue) != 1:
raise ExpressionParserError("Invalid expression")

return self.queue[0]
1 change: 1 addition & 0 deletions tests/test_expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ def test_expression(expression: str, answer: int) -> None:
("-", ExpressionParserError, "Invalid expression: not enough operands"),
("(", ExpressionParserError, "Invalid expression"),
(")", ExpressionParserError, "Invalid expression"),
(" ", ExpressionParserError, "Invalid expression"),
("()", ExpressionParserError, "Parser expected an expression, instead received empty parenthesis. Index: 1"),
("0()", ExpressionParserError, "Parser expected sizeof or an arethmethic operator instead got: '0'"),
("sizeof)", ExpressionParserError, "Invalid sizeof operation"),
Expand Down

0 comments on commit a72aaae

Please sign in to comment.