Mike Rosing on Mon, 23 Feb 2015 22:53:01 +0100


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: Now what am I doing wrong?


I figured it out - The limit should be i<k not i<=k.
so I ran off the end of the pointers.

On Mon, 23 Feb 2015, Mike Rosing wrote:

I have a really simple program:

#include <pari/pari.h>

int main()
{
 GEN f, num, sum;
 int i, k;

 pari_init(2*1024*1024, 5*1024*512);
 f = factor(stoi(20765));
 pari_printf("%Ps\n", f);
 num = gel(f, 2);
 sum = gen_0;
 k =lg(num);
 for(i=1; i<=k; i++)
 {
   sum = gadd(sum, gel(num, i));
   pari_printf("%d  %Pd\n", i, sum);
 }
 return 0;
}

which dies at the end of the for loop:

$ ./bug-dyn
[5, 1; 4153, 1]
1  1
2  2
 ***   bug in PARI/GP (Segmentation Fault), please report.
 ***   Error in the PARI system. End of program.

The value of sum is always correct, but exiting the for loop crashes the program. What am I doing wrong?

Thanks!