[BUGFIX] Prevent crashes in find_common_factor()
authorVladimir V. Kisil <V.Kisil@leeds.ac.uk>
Mon, 22 Jun 2020 07:49:00 +0000 (09:49 +0200)
committerRichard Kreckel <kreckel@ginac.de>
Mon, 22 Jun 2020 07:49:00 +0000 (09:49 +0200)
These happened if a non-normalised common factor was equal to zero.

Thanks to Feng Feng for reporting this bug.

ginac/normal.cpp

index a80e15084c3affee06491acdba6013aaae0ee2ee..8e44bee24db29555bb4ad43794b560bcabc17ad3 100644 (file)
@@ -2565,7 +2565,7 @@ static ex find_common_factor(const ex & e, ex & factor, exmap & repl)
                                x *= f;
                        }
 
                                x *= f;
                        }
 
-                       if (i == 0)
+                       if (gc.is_zero())
                                gc = x;
                        else
                                gc = gcd(gc, x);
                                gc = x;
                        else
                                gc = gcd(gc, x);
@@ -2576,6 +2576,9 @@ static ex find_common_factor(const ex & e, ex & factor, exmap & repl)
                if (gc.is_equal(_ex1))
                        return e;
 
                if (gc.is_equal(_ex1))
                        return e;
 
+               if (gc.is_zero())
+                       return _ex0;
+
                // The GCD is the factor we pull out
                factor *= gc;
 
                // The GCD is the factor we pull out
                factor *= gc;