This is the mail archive of the
libc-alpha@sourceware.cygnus.com
mailing list for the glibc project.
Re: [A K KARTIK <akkartik@mailcity.com>] libc/1158: glibc: segmentation fault within malloc
- To: aj@arthur.rhein-neckar.de
- Subject: Re: [A K KARTIK <akkartik@mailcity.com>] libc/1158: glibc: segmentation fault within malloc
- From: Geoff Keating <geoffk@ozemail.com.au>
- Date: Sat, 12 Jun 1999 23:27:28 +1000
- CC: libc-alpha@sourceware.cygnus.com
- References: <u8g13xapqc.fsf@arthur.rhein-neckar.de>
> From: Andreas Jaeger <aj@arthur.rhein-neckar.de>
> Date: 12 Jun 1999 08:37:47 +0200
> Could anybody with c++ knowledge look into the appended bug report and
> tell us what's wrong? I get the same error with glibc 2.1.1.
...
> void network :: init (int d, int conn, int sz [MAX_DIM]) {
> int i ;
>
> total_size = 1 ;
> for (i = 0; i < MAX_DIM; i++) {
> if (sz [i] == 0) break ;
> size [i] = sz [i] ;
> total_size *= sz [i] ;
> }
>
> actnode = (node*) malloc (total_size * sizeof (actnode)) ;
I think this is the faulty line. Shouldn't it be
`total_size*sizeof(actnode[0])'? A `node' is much larger than a
`node *'.
When I fix this, the program runs happily on my machine, where before
it did indeed segfault.
--
Geoffrey Keating <geoffk@ozemail.com.au>