Package: pari
Version: 2.8.0


I have a strange bug that I can trigger intermittently while in a breakloop. I've minimized the example as much as possible and ensured that it occurs on a clean startup.

First I define a function a, then I execute it in a loop. While in the loop I press Ctrl+C and it gives me the break> prompt as expected. When I ask for the loop variable I get a segfault... but only sometimes:

(14:26) gp >a(n)=sum(a=0,sqrtnint(n,3), sum(b=0,a, my(C=n-a^3-b^3,c); ispower(C,3)))
(14:26) gp >for(n=0,1e7,a(n))
  ***   at top-level: for(n=0,1e7,a(n))
  ***                             ^-----
  ***   in function a: ...n,3),sum(b=0,a,my(C=n-a^3-b^3,c);ispower(C,3)
  ***                                              ^--------------------
  *** _-_: user interrupt after 1,093 ms
  ***   Break loop: <Return> to continue; 'break' to go back to GP prompt
break> n
17945
break>

(14:26) gp >for(n=0,1e7,a(n))
  ***   at top-level: for(n=0,1e7,a(n))
  ***                             ^-----
  ***   in function a: ...,sqrtnint(n,3),sum(b=0,a,my(C=n-a^3-b^3,c);is
  ***                                              ^--------------------
  ***   user interrupt after 1,142 ms
  ***   Break loop: <Return> to continue; 'break' to go back to GP prompt
break> n
  ***   at top-level: for(n=0,1e7,a(n))
  ***                             ^-----
  ***   in function a: ...,sqrtnint(n,3),sum(b=0,a,my(C=n-a^3-b^3,c);is
  ***                                              ^--------------------
  ***   in function my: n
  ***                   ^-
  ***   bug in PARI/GP (Segmentation Fault), please report.
  ***   Break loop: type 'break' to go back to GP prompt
break[2]>

In my tests the segfault happens about half the time (5 out of 12 so far).

Strangely, if I change the function definition to remove the local variable c
a(n)=sum(a=0,sqrtnint(n,3), sum(b=0,a, my(C=n-a^3-b^3); ispower(C,3)))
I can't reproduce the segfault (in 25 attempts).

I don't see this as a major issue, segfault notwithstanding, but I thought it should be reported. Certainly I find the behavior puzzling.

Charles Greathouse
Case Western Reserve University