[prev in list] [next in list] [prev in thread] [next in thread] 

List:       gmp-discuss
Subject:    Memory allocation problem!
From:       daggillies () gmail ! com (David Gillies)
Date:       2011-09-04 14:48:32
Message-ID: CANGHvuBcyZMbwoRrcjrmpXQE0a2Zj1uYEroZupT4WteYYLY5NQ () mail ! gmail ! com
[Download RAW message or body]

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

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic