diff options
| author | Richard M. Stallman | 1993-05-31 03:39:07 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1993-05-31 03:39:07 +0000 |
| commit | 87fbf902fdc0acf4ce52b83843addfae1d4eb402 (patch) | |
| tree | 76bd29e90faf72082f21e9c855c3316e49058de9 /src/data.c | |
| parent | 483288d7449b955902061fef1cfa84f7c770850e (diff) | |
| download | emacs-87fbf902fdc0acf4ce52b83843addfae1d4eb402.tar.gz emacs-87fbf902fdc0acf4ce52b83843addfae1d4eb402.zip | |
(float_arith_driver): Detect division by zero in advance.
(arith_driver, Frem): Likewise.
Diffstat (limited to 'src/data.c')
| -rw-r--r-- | src/data.c | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/src/data.c b/src/data.c index e56e30ed6df..c5564158984 100644 --- a/src/data.c +++ b/src/data.c | |||
| @@ -1550,8 +1550,7 @@ enum arithop | |||
| 1550 | extern Lisp_Object float_arith_driver (); | 1550 | extern Lisp_Object float_arith_driver (); |
| 1551 | 1551 | ||
| 1552 | Lisp_Object | 1552 | Lisp_Object |
| 1553 | arith_driver | 1553 | arith_driver (code, nargs, args) |
| 1554 | (code, nargs, args) | ||
| 1555 | enum arithop code; | 1554 | enum arithop code; |
| 1556 | int nargs; | 1555 | int nargs; |
| 1557 | register Lisp_Object *args; | 1556 | register Lisp_Object *args; |
| @@ -1607,7 +1606,12 @@ arith_driver | |||
| 1607 | case Amult: accum *= next; break; | 1606 | case Amult: accum *= next; break; |
| 1608 | case Adiv: | 1607 | case Adiv: |
| 1609 | if (!argnum) accum = next; | 1608 | if (!argnum) accum = next; |
| 1610 | else accum /= next; | 1609 | else |
| 1610 | { | ||
| 1611 | if (next == 0) | ||
| 1612 | Fsignal (Qarith_error, Qnil); | ||
| 1613 | accum /= next; | ||
| 1614 | } | ||
| 1611 | break; | 1615 | break; |
| 1612 | case Alogand: accum &= next; break; | 1616 | case Alogand: accum &= next; break; |
| 1613 | case Alogior: accum |= next; break; | 1617 | case Alogior: accum |= next; break; |
| @@ -1668,7 +1672,11 @@ float_arith_driver (accum, argnum, code, nargs, args) | |||
| 1668 | if (!argnum) | 1672 | if (!argnum) |
| 1669 | accum = next; | 1673 | accum = next; |
| 1670 | else | 1674 | else |
| 1671 | accum /= next; | 1675 | { |
| 1676 | if (next == 0) | ||
| 1677 | Fsignal (Qarith_error, Qnil); | ||
| 1678 | accum /= next; | ||
| 1679 | } | ||
| 1672 | break; | 1680 | break; |
| 1673 | case Alogand: | 1681 | case Alogand: |
| 1674 | case Alogior: | 1682 | case Alogior: |
| @@ -1746,6 +1754,9 @@ Both must be numbers or markers.") | |||
| 1746 | 1754 | ||
| 1747 | f1 = XTYPE (num1) == Lisp_Float ? XFLOAT (num1)->data : XINT (num1); | 1755 | f1 = XTYPE (num1) == Lisp_Float ? XFLOAT (num1)->data : XINT (num1); |
| 1748 | f2 = XTYPE (num2) == Lisp_Float ? XFLOAT (num2)->data : XINT (num2); | 1756 | f2 = XTYPE (num2) == Lisp_Float ? XFLOAT (num2)->data : XINT (num2); |
| 1757 | if (f2 == 0) | ||
| 1758 | Fsignal (Qarith_error, Qnil); | ||
| 1759 | |||
| 1749 | #if defined (USG) || defined (sun) || defined (ultrix) || defined (hpux) | 1760 | #if defined (USG) || defined (sun) || defined (ultrix) || defined (hpux) |
| 1750 | f1 = fmod (f1, f2); | 1761 | f1 = fmod (f1, f2); |
| 1751 | #else | 1762 | #else |
| @@ -1760,6 +1771,9 @@ Both must be numbers or markers.") | |||
| 1760 | CHECK_NUMBER_COERCE_MARKER (num2, 1); | 1771 | CHECK_NUMBER_COERCE_MARKER (num2, 1); |
| 1761 | #endif /* not LISP_FLOAT_TYPE */ | 1772 | #endif /* not LISP_FLOAT_TYPE */ |
| 1762 | 1773 | ||
| 1774 | if (XFASTINT (num2) == 0) | ||
| 1775 | Fsignal (Qarith_error, Qnil); | ||
| 1776 | |||
| 1763 | XSET (val, Lisp_Int, XINT (num1) % XINT (num2)); | 1777 | XSET (val, Lisp_Int, XINT (num1) % XINT (num2)); |
| 1764 | return val; | 1778 | return val; |
| 1765 | } | 1779 | } |