>From 888bbb563efe4a67f22ab4106fc292f3ebd39b28 Mon Sep 17 00:00:00 2001
From: "Vladimir V. Kisil" <V.Kisilv@leeds.ac.uk>
Date: Fri, 19 Jun 2020 20:05:13 +0100
Subject: [PATCH] Prevent crashes in find_common_factor()

These happened if a non-normalised common factor was equal to zero.

Signed-off-by: Vladimir V. Kisil <V.Kisilv@leeds.ac.uk>
---
 ginac/normal.cpp | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/ginac/normal.cpp b/ginac/normal.cpp
index b2afb7de..c234a86f 100644
--- a/ginac/normal.cpp
+++ b/ginac/normal.cpp
@@ -2719,7 +2719,7 @@ static ex find_common_factor(const ex & e, ex & factor, exmap & repl)
 				x *= f;
 			}
 
-			if (i == 0)
+			if (gc.is_zero())
 				gc = x;
 			else
 				gc = gcd(gc, x);
@@ -2730,6 +2730,9 @@ static ex find_common_factor(const ex & e, ex & factor, exmap & repl)
 		if (gc.is_equal(_ex1))
 			return e;
 
+		if (gc.is_zero())
+			return _ex0;
+
 		// The GCD is the factor we pull out
 		factor *= gc;
 
-- 
2.27.0

