factorize.c code problem noticed

Randall Rathbun randallrathbun at gmail.com
Tue Jan 17 08:12:47 UTC 2017


Not a bug, but a good suggestion
-------------- next part --------------
Suggested fixes for the factorize.c program in the ~/gmp-6.1.2/demos folder area

53,54c53,54
<   factors->p = malloc (1);
<   factors->e = malloc (1);
---
>   factors->p = (mpz_t*) malloc (sizeof(mpz_t*));
>   factors->e = (unsigned long int*) malloc (sizeof(unsigned long int*));
87,88c87,88
<       p = realloc (p, (nfactors + 1) * sizeof p[0]);
<       e = realloc (e, (nfactors + 1) * sizeof e[0]);
---
>       p = (mpz_t*) realloc (p, (nfactors + 1) * sizeof p[0]);
>       e = (unsigned long int*) realloc (e, (nfactors + 1) * sizeof e[0]);
408a409
> 
414a416,418
>      if (mpz_sgn(t) == -1)
>        mpz_neg(t,t);
> 
432a437,439
> 
>      if (mpz_sgn(t) == -1)
>        mpz_neg(t,t);

Thread model: posix
gcc version 4.8.5 (SUSE Linux) 

The first fix should have been used in C code anyways, while the 2nd fix stops the unterminating loop if a negative value is accidently entered.



More information about the gmp-bugs mailing list