about summary refs log tree commit diff
path: root/Src/math.c
diff options
context:
space:
mode:
authorOliver Kiddle <okiddle@yahoo.co.uk>2018-05-13 10:13:42 +0200
committerOliver Kiddle <okiddle@yahoo.co.uk>2018-05-13 10:13:42 +0200
commita93abe1170a438d45d94b3a7f924553f5cf69cee (patch)
tree95cc9a6832acc5ece693389209531eeefdc10f88 /Src/math.c
parent373efa085dcea5fe6b4539cd875b6bd8645f16fa (diff)
downloadzsh-a93abe1170a438d45d94b3a7f924553f5cf69cee.tar.gz
zsh-a93abe1170a438d45d94b3a7f924553f5cf69cee.tar.xz
zsh-a93abe1170a438d45d94b3a7f924553f5cf69cee.zip
42488: test cases for 42369 and address some issues in the code
Diffstat (limited to 'Src/math.c')
-rw-r--r--Src/math.c37
1 files changed, 19 insertions, 18 deletions
diff --git a/Src/math.c b/Src/math.c
index cdfe80bb4..32bccc6e9 100644
--- a/Src/math.c
+++ b/Src/math.c
@@ -593,7 +593,6 @@ isinf(double x)
 #endif
 
 #if !defined(HAVE_ISNAN)
-/**/
 static double
 store(double *x)
 {
@@ -816,27 +815,11 @@ zzlex(void)
 		ptr++;
 		break;
 	    }
-	case ' ':
+	case ' ': /* Fall through! */
 	case '\t':
 	case '\n':
 	    break;
-	/* Fall through! */
 	default:
-	    if (strcmp(ptr-1, "NaN") == 0) {
-		yyval.type = MN_FLOAT;
-		yyval.u.d = 0.0;
-		yyval.u.d /= yyval.u.d;
-		ptr += 2;
-		return NUM;
-	    }
-	    else if (strcmp(ptr-1, "Inf") == 0) {
-		yyval.type = MN_FLOAT;
-		yyval.u.d = 0.0;
-		yyval.u.d = 1.0 / yyval.u.d;
-		ptr += 2;
-		return NUM;
-	    }
-
 	    if (idigit(*--ptr) || *ptr == '.')
 		return lexconstant();
 	    if (*ptr == '#') {
@@ -860,6 +843,20 @@ zzlex(void)
 
 		p = ptr;
 		ptr = ie;
+		if (ie - p == 3) {
+		    if (strncasecmp(p, "NaN", 3) == 0) {
+			yyval.type = MN_FLOAT;
+			yyval.u.d = 0.0;
+			yyval.u.d /= yyval.u.d;
+			return NUM;
+		    }
+		    else if (strncasecmp(p, "Inf", 3) == 0) {
+			yyval.type = MN_FLOAT;
+			yyval.u.d = 0.0;
+			yyval.u.d = 1.0 / yyval.u.d;
+			return NUM;
+		    }
+		}
 		if (*ptr == '[' || (!cct && *ptr == '(')) {
 		    char op = *ptr, cp = ((*ptr == '[') ? ']' : ')');
 		    int l;
@@ -1114,6 +1111,10 @@ callmathfunc(char *o)
 static int
 notzero(mnumber a)
 {
+    if ((a.type & MN_INTEGER) && a.u.l == 0) {
+        zerr("division by zero");
+        return 0;
+    }
     return 1;
 }