Memory allocation problem!

David Gillies daggillies at gmail.com
Sun Sep 4 16:48:32 CEST 2011


On Sat, Sep 3, 2011 at 4:24 PM,  <bodrato at mail.dm.unipi.it> wrote:
> Ciao,
>
> Il Sab, 3 Settembre 2011 11:42 pm, laojiang ha scritto:
>> Hi, I have a problem,such as I definite a one dimension array, and
>
>>  f_f0= ( mpf_t *)malloc(n0 * sizeof( mpf_t *));
>
>>   for (n = 0; n < n0+1; n++)
>>     {
>>       mpf_init(f_f0[n]);
>>      }
>
> You allocate memory for n0 pointers, then you use n0+1 of them...
> This error is not related to GMP in any way, it will fail the same way if
> you replace mpf_t with double.
>
> --
> http://bodrato.it/
>
> _______________________________________________
> gmp-discuss mailing list
> gmp-discuss at gmplib.org
> https://gmplib.org/mailman/listinfo/gmp-discuss
>

The only thing I wish is that you could get memory managers to
_reliably_ fall over when you make a rookie mistake like this. I think
most of us have spent many hours sweating blood over heap corruption
bugs, at least in the days before things like Valgrind and dmalloc.
Fence-post errors can be less blatant than this.

-- 
David Gillies
San Jose
Costa Rica


More information about the gmp-discuss mailing list