From 3a5bedf702e66b53654da57e945516f39866abfe Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Tue, 4 Feb 2014 20:19:13 -0600 Subject: [PATCH] Fix constant || and && evaluation - When SendExprCommand() evaluates constant expressions for || and &&, it must explicitly pop both operands off the stack before pushing the result. The compiler will do normal short-circuiting here, so if it only needs one value to determine the result, only one would be popped off the stack. --- parse.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/parse.c b/parse.c index d04ad5c..e6d63f0 100644 --- a/parse.c +++ b/parse.c @@ -3771,7 +3771,7 @@ static void ConstExprFactor(void) static void SendExprCommand(pcd_t pcd) { - int operand2; + int operand1, operand2; if(ConstantExpression == NO) { @@ -3821,10 +3821,14 @@ static void SendExprCommand(pcd_t pcd) PushExStk(PopExStk() < operand2); break; case PCD_ANDLOGICAL: - PushExStk(PopExStk() && PopExStk()); + operand2 = PopExStk(); + operand1 = PopExStk(); + PushExStk(operand1 && operand2); break; case PCD_ORLOGICAL: - PushExStk(PopExStk() || PopExStk()); + operand2 = PopExStk(); + operand1 = PopExStk(); + PushExStk(operand1 || operand2); break; case PCD_ANDBITWISE: PushExStk(PopExStk()&PopExStk());