mirror of
https://github.com/cc65/cc65.git
synced 2025-08-12 17:25:11 +00:00
Check for division by/modulo by zero when parsing the /= and %= operators.
git-svn-id: svn://svn.cc65.org/cc65/trunk@3937 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
@@ -1878,7 +1878,7 @@ static void hie_compare (const GenDesc* Ops, /* List of generators */
|
|||||||
Error ("Incompatible types");
|
Error ("Incompatible types");
|
||||||
}
|
}
|
||||||
} else if (!ED_IsNullPtr (&Expr2)) {
|
} else if (!ED_IsNullPtr (&Expr2)) {
|
||||||
Error ("Incompatible types");
|
Error ("Incompatible types");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1931,7 +1931,7 @@ static void hie_compare (const GenDesc* Ops, /* List of generators */
|
|||||||
if (rconst) {
|
if (rconst) {
|
||||||
flags |= CF_CONST;
|
flags |= CF_CONST;
|
||||||
if ((Gen->Flags & GEN_NOPUSH) != 0) {
|
if ((Gen->Flags & GEN_NOPUSH) != 0) {
|
||||||
RemoveCode (&Mark2);
|
RemoveCode (&Mark2);
|
||||||
ltype |= CF_REG; /* Value is in register */
|
ltype |= CF_REG; /* Value is in register */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2090,7 +2090,7 @@ static void parseadd (ExprDesc* Expr)
|
|||||||
*/
|
*/
|
||||||
if (ED_IsLocAbs (Expr)) {
|
if (ED_IsLocAbs (Expr)) {
|
||||||
/* Numeric constant, scale lhs */
|
/* Numeric constant, scale lhs */
|
||||||
Expr->IVal *= ScaleFactor;
|
Expr->IVal *= ScaleFactor;
|
||||||
/* Generate the code for the add */
|
/* Generate the code for the add */
|
||||||
g_inc (flags, Expr->IVal);
|
g_inc (flags, Expr->IVal);
|
||||||
} else if (ScaleFactor == 1) {
|
} else if (ScaleFactor == 1) {
|
||||||
@@ -2196,7 +2196,7 @@ static void parseadd (ExprDesc* Expr)
|
|||||||
flags = typeadjust (Expr, &Expr2, 0) & ~CF_CONST;
|
flags = typeadjust (Expr, &Expr2, 0) & ~CF_CONST;
|
||||||
} else {
|
} else {
|
||||||
/* OOPS */
|
/* OOPS */
|
||||||
Error ("Invalid operands for binary operator `+'");
|
Error ("Invalid operands for binary operator `+'");
|
||||||
flags = CF_INT;
|
flags = CF_INT;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2302,7 +2302,7 @@ static void parsesub (ExprDesc* Expr)
|
|||||||
} else {
|
} else {
|
||||||
rscale = CheckedPSizeOf (lhst);
|
rscale = CheckedPSizeOf (lhst);
|
||||||
}
|
}
|
||||||
/* Operate on pointers, result type is an integer */
|
/* Operate on pointers, result type is an integer */
|
||||||
flags = CF_PTR;
|
flags = CF_PTR;
|
||||||
Expr->Type = type_int;
|
Expr->Type = type_int;
|
||||||
} else if (IsClassInt (lhst) && IsClassInt (rhst)) {
|
} else if (IsClassInt (lhst) && IsClassInt (rhst)) {
|
||||||
@@ -2355,7 +2355,7 @@ static void parsesub (ExprDesc* Expr)
|
|||||||
* longer true, lhs is on stack instead.
|
* longer true, lhs is on stack instead.
|
||||||
*/
|
*/
|
||||||
if (ED_IsLocAbs (Expr)) {
|
if (ED_IsLocAbs (Expr)) {
|
||||||
ED_MakeRValExpr (Expr);
|
ED_MakeRValExpr (Expr);
|
||||||
}
|
}
|
||||||
/* Adjust operand types */
|
/* Adjust operand types */
|
||||||
flags = typeadjust (Expr, &Expr2, 0);
|
flags = typeadjust (Expr, &Expr2, 0);
|
||||||
@@ -2842,7 +2842,15 @@ static void opeq (const GenDesc* Gen, ExprDesc* Expr)
|
|||||||
g_inc (flags | CF_CONST, Expr2.IVal);
|
g_inc (flags | CF_CONST, Expr2.IVal);
|
||||||
} else if (Gen->Func == g_sub) {
|
} else if (Gen->Func == g_sub) {
|
||||||
g_dec (flags | CF_CONST, Expr2.IVal);
|
g_dec (flags | CF_CONST, Expr2.IVal);
|
||||||
} else {
|
} else {
|
||||||
|
if (Expr2.IVal == 0) {
|
||||||
|
/* Check for div by zero/mod by zero */
|
||||||
|
if (Gen->Func == g_div) {
|
||||||
|
Error ("Division by zero");
|
||||||
|
} else if (Gen->Func == g_mod) {
|
||||||
|
Error ("Modulo operation with zero");
|
||||||
|
}
|
||||||
|
}
|
||||||
Gen->Func (flags | CF_CONST, Expr2.IVal);
|
Gen->Func (flags | CF_CONST, Expr2.IVal);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
Reference in New Issue
Block a user