changeset 3338:30b946dd8c66

(float_arith_driver): Detect division by zero in advance. (arith_driver, Frem): Likewise.
author Richard M. Stallman <rms@gnu.org>
date Mon, 31 May 1993 03:39:07 +0000
parents f5f76ebe6286
children a76734c7dcc5
files src/data.c
diffstat 1 files changed, 18 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/data.c	Mon May 31 02:59:19 1993 +0000
+++ b/src/data.c	Mon May 31 03:39:07 1993 +0000
@@ -1550,8 +1550,7 @@
 extern Lisp_Object float_arith_driver ();
 
 Lisp_Object
-arith_driver
-  (code, nargs, args)
+arith_driver (code, nargs, args)
      enum arithop code;
      int nargs;
      register Lisp_Object *args;
@@ -1607,7 +1606,12 @@
 	case Amult: accum *= next; break;
 	case Adiv:
 	  if (!argnum) accum = next;
-	  else accum /= next;
+	  else
+	    {
+	      if (next == 0)
+		Fsignal (Qarith_error, Qnil);
+	      accum /= next;
+	    }
 	  break;
 	case Alogand: accum &= next; break;
 	case Alogior: accum |= next; break;
@@ -1668,7 +1672,11 @@
 	  if (!argnum)
 	    accum = next;
 	  else
-	    accum /= next;
+	    {
+	      if (next == 0)
+		Fsignal (Qarith_error, Qnil);
+	      accum /= next;
+	    }
 	  break;
 	case Alogand:
 	case Alogior:
@@ -1746,6 +1754,9 @@
 
       f1 = XTYPE (num1) == Lisp_Float ? XFLOAT (num1)->data : XINT (num1);
       f2 = XTYPE (num2) == Lisp_Float ? XFLOAT (num2)->data : XINT (num2);
+      if (f2 == 0)
+	Fsignal (Qarith_error, Qnil);
+
 #if defined (USG) || defined (sun) || defined (ultrix) || defined (hpux)
       f1 = fmod (f1, f2);
 #else
@@ -1760,6 +1771,9 @@
   CHECK_NUMBER_COERCE_MARKER (num2, 1);
 #endif /* not LISP_FLOAT_TYPE */
 
+  if (XFASTINT (num2) == 0)
+    Fsignal (Qarith_error, Qnil);
+
   XSET (val, Lisp_Int, XINT (num1) % XINT (num2));
   return val;
 }