Bill Allombert on Thu, 2 Oct 2003 20:52:11 +0200


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

qfbprimeform(-3,1)--> stack corruption


Hello PARI-Dev,

? qfbprimeform(-3,1)
%1 = Qfb(1, 1, 33554435)

This looks like a stack corruption do to an abuse of setsigne(y[3],1).
Unfortunately, there is no warranty that a PARI function return a value
on the stack rather than gzero or gun. If we can restrain ourself to use
such hack, we should write a macro that do it correctly.


Here a not very good patch:

--- src/basemath/arith2.c       Thu Oct  2 19:31:13 2003
+++ ../src/pari/src/basemath/arith2.c   Wed Sep 17 11:49:12 2003
@@ -1669,7 +1669,7 @@
   GEN y = cgetg(4,t_QFI);
   long isodd;

-  if (typ(D) != t_INT || signe(D) >= 0) err(typeer,"imag_unit_form_by_disc");
+  if (typ(D) != t_INT || signe(D) >= 0) err(typeer,"real_unit_form_by_disc");
   switch(4 - mod4(D))
   {
     case 2:
@@ -1678,7 +1678,7 @@
   y[1] = un; isodd = mpodd(D);
   y[2] = isodd? un: zero;
   /* y[3] = (1-D) / 4 or -D / 4, whichever is an integer */
-  y[3] = lshifti(D,-2); if(signe(y[3])==-1) setsigne(y[3],1);
+  y[3] = lshifti(D,-2); setsigne(y[3],1);
   if (isodd)
   {
     pari_sp av = avma;

Cheers,
Bill.