Skip to content

Commit 8272c9f

Browse files
committed
Fix error 094 not being printed if the dividend is not a constant value
1 parent 73d102b commit 8272c9f

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

source/compiler/sc3.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,10 @@ static void plnge2(void (*oper)(void),
620620
} /* if */
621621
/* ??? ^^^ should do same kind of error checking with functions */
622622

623+
/* If we're handling a division operation, make sure the divisor is not zero. */
624+
if ((oper==os_div || oper==os_mod) && lval2->ident==iCONSTEXPR && lval2->constval==0)
625+
error(94); /* division by zero */
626+
623627
/* check whether an "operator" function is defined for the tag names
624628
* (a constant expression cannot be optimized in that case)
625629
*/
@@ -643,10 +647,8 @@ static cell flooreddiv(cell a,cell b,int return_remainder)
643647
{
644648
cell q,r;
645649

646-
if (b==0) {
647-
error(94); /* division by zero */
650+
if (b==0)
648651
return 0;
649-
} /* if */
650652
/* first implement truncated division in a portable way */
651653
#define IABS(a) ((a)>=0 ? (a) : (-a))
652654
q=IABS(a)/IABS(b);

0 commit comments

Comments
 (0)