summaryrefslogtreecommitdiff
path: root/src/factor.c
diff options
context:
space:
mode:
authorNiels Möller <nisse@lysator.liu.se>2016-12-08 09:48:50 +0000
committerPádraig Brady <P@draigBrady.com>2016-12-08 10:10:34 +0000
commitc44da115063bfea7ef8b2afd1c9d52737e2b7f70 (patch)
treec90c88e701c97f5272917e60a553cbcd0c40956f /src/factor.c
parent11c1b73c1b386a098e5e18af864591541b63d7bf (diff)
downloadcoreutils-c44da115063bfea7ef8b2afd1c9d52737e2b7f70.tar.xz
factor: fix infinite loop in gcd2_odd
* src/factor.c (gcd2_odd): Fix the case a1 == 0, a0 == 0. * NEWS: Mention the bug fix. Fixes http://bugs.gnu.org/25135
Diffstat (limited to 'src/factor.c')
-rw-r--r--src/factor.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/factor.c b/src/factor.c
index d271de907..115a635f9 100644
--- a/src/factor.c
+++ b/src/factor.c
@@ -480,10 +480,16 @@ gcd_odd (uintmax_t a, uintmax_t b)
static uintmax_t
gcd2_odd (uintmax_t *r1, uintmax_t a1, uintmax_t a0, uintmax_t b1, uintmax_t b0)
{
+ assert (b0 & 1);
+
+ if ( (a0 | a1) == 0)
+ {
+ *r1 = b1;
+ return b0;
+ }
+
while ((a0 & 1) == 0)
rsh2 (a1, a0, a1, a0, 1);
- while ((b0 & 1) == 0)
- rsh2 (b1, b0, b1, b0, 1);
for (;;)
{