This is not a GMP bug, but a coding bug in "factorize.c" which is included in the demos folder. You can see the bug in action by making factorize and executing the following line:
at which point the program appears to hang. It isn't really hung, though. What's happening is that for one particular (rare) path in the code a certain variable (k) in the routine "factor_using_pollard_rho" is decremented from zero to -1, which then acts as 2^32-1 in a loop (resulting in a very long loop!) Specifically, here's the offending code:
k = 1;
while (mpz_cmp_ui (n, 1) != 0)
{
S2:
... (k is not affected here)
S3:
k--;
if (k != 0)
goto S2;
For bad behavior, k is equal to 1 at the S3 point, is decremented to zero, and falls through to the gcd call. If the
gcd is greater than 1, then the code jumps to S4 and then back to S2 without altering k. When it gets decremented again (to -1), we enter the long loop. To fix this, I changed the "if (k != 0)" statement to "if(k > 0)", which seems to work. The correct output for the input above is