From 59dd8d3c51467c79702666efc80b6f033b9fd32c Mon Sep 17 00:00:00 2001 From: Matthew Kilgore Date: Sat, 24 Sep 2022 12:15:46 -0400 Subject: [PATCH] Fix undefined variables in CONST expressions to trigger an error Overall this is fairly straight forward, `evaluateconst$` has type information on the parameters for its expressions, but it's not actually checking that both parameters have a proper type. The result is that expressions with nonsense values such as undefined variable names end up just trying to use that nonsense value as an integer. Fixes: #177 --- source/qb64pe.bas | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/source/qb64pe.bas b/source/qb64pe.bas index 95e4522bc..2c2290246 100644 --- a/source/qb64pe.bas +++ b/source/qb64pe.bas @@ -23735,6 +23735,11 @@ FUNCTION evaluateconst$ (a2$, t AS LONG) 'string/numeric mismatch? IF (btype(i) AND ISSTRING) <> (et AND ISSTRING) THEN Give_Error "Invalid CONST expression.11": EXIT FUNCTION + ' The left and right operands needs to have valid types. They might not if + ' the user wrote something invalid like `1 OR OR 2` + IF et = 0 THEN Give_Error "Invalid CONST expression.14": EXIT FUNCTION + IF btype(i) = 0 THEN Give_Error "Invalid CONST expression.15": EXIT FUNCTION + IF et AND ISSTRING THEN IF o$ <> "+" THEN Give_Error "Invalid CONST expression.12": EXIT FUNCTION 'concat strings