mpq_t array in sub-functions

delta trinity deltatrinity@hotmail.com
Tue, 11 Mar 2003 12:44:24 -0500


Simple programing mistake, not GMP related really... ;-)

What happen is that in the function:
----------------------------
void assignValue(mpq_t x[], int size){
   mpq_t *R;
   initPoly(&R,15);

   assignValue2(R,size);
   assignValue3(x,size);

   clearPoly(R,15);
}
----------------------------

You initialize R as an array of 15 mpq_t (hardcoded value).
Then, in the main, when you come to call

   assignValue(B,20);

this create a bug, in the assignValue function, when comming to
{
   ...
   assignValue2(R,size);
   ...
}

which assign values to R as an array of 'size' (20 in this case) when R is 
allocated only 15 mpq_t

Eric

>From: "E Lau" <elau@hotmail.com>
>To: gmp-discuss@swox.com
>CC: elau@hotmail.com
>Subject: mpq_t array in sub-functions
>Date: Tue, 11 Mar 2003 00:25:22 -0500
>
>Hi all:
>
>I am new to GMP, so I was wondering if someone can give me a hint here.  I 
>was trying to define an array in mpq_t.  It works fine when I define this 
>array in the main function.  However, when I define this array in a sub 
>function, the program generate seg fault.  I attached the sample C file 
>here.  The function "void assignValue(mpq_t x[], int size)" contains 4 
>commented-out lines of code which are causing seg faults in the simple test 
>program.
>
>I'm open to comments and suggestions.  Thanks.
>
>
>Sincerely,
>
>Edmond Lau


_________________________________________________________________
STOP MORE SPAM with the new MSN 8 and get 2 months FREE*  
http://join.msn.com/?page=features/junkmail