mirror of
https://github.com/ZDoom/acc.git
synced 2024-11-30 07:30:52 +00:00
Merge pull request #26 from edward-san/div_by_zero
- Fixed the 'division by zero' crash in the constant expression parsing.
This commit is contained in:
commit
ae5f03691a
3 changed files with 12 additions and 4 deletions
1
error.c
1
error.c
|
@ -104,6 +104,7 @@ static struct
|
|||
{ ERR_MISSING_COLON, "Missing colon." },
|
||||
{ ERR_BAD_EXPR, "Syntax error in expression." },
|
||||
{ ERR_BAD_CONST_EXPR, "Syntax error in constant expression." },
|
||||
{ ERR_DIV_BY_ZERO_IN_CONST_EXPR, "Division by zero in constant expression." },
|
||||
{ ERR_NO_DIRECT_VER, "Internal function has no direct version." },
|
||||
{ ERR_ILLEGAL_EXPR_IDENT, "%s : Illegal identifier in expression." },
|
||||
{ ERR_EXPR_FUNC_NO_RET_VAL, "Function call in expression has no return value." },
|
||||
|
|
1
error.h
1
error.h
|
@ -69,6 +69,7 @@ typedef enum
|
|||
ERR_MISSING_COLON,
|
||||
ERR_BAD_EXPR,
|
||||
ERR_BAD_CONST_EXPR,
|
||||
ERR_DIV_BY_ZERO_IN_CONST_EXPR,
|
||||
ERR_NO_DIRECT_VER,
|
||||
ERR_ILLEGAL_EXPR_IDENT,
|
||||
ERR_EXPR_FUNC_NO_RET_VAL,
|
||||
|
|
14
parse.c
14
parse.c
|
@ -3807,12 +3807,18 @@ static void SendExprCommand(pcd_t pcd)
|
|||
PushExStk(PopExStk()*PopExStk());
|
||||
break;
|
||||
case PCD_DIVIDE:
|
||||
operand2 = PopExStk();
|
||||
PushExStk(PopExStk()/operand2);
|
||||
break;
|
||||
case PCD_MODULUS:
|
||||
operand2 = PopExStk();
|
||||
PushExStk(PopExStk()%operand2);
|
||||
operand1 = PopExStk();
|
||||
if (operand2 != 0)
|
||||
{
|
||||
PushExStk(pcd == PCD_DIVIDE ? operand1/operand2 : operand1%operand2);
|
||||
}
|
||||
else
|
||||
{
|
||||
ERR_Error(ERR_DIV_BY_ZERO_IN_CONST_EXPR, YES);
|
||||
PushExStk(operand1);
|
||||
}
|
||||
break;
|
||||
case PCD_EQ:
|
||||
PushExStk(PopExStk() == PopExStk());
|
||||
|
|
Loading…
Reference in a new issue