[A K KARTIK <akkartik@mailcity.com>] libc/1158: glibc: segmentation fault within malloc
Geoff Keating
geoffk@ozemail.com.au
Sat Jun 12 22:25:00 GMT 1999
> 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>
More information about the Libc-alpha
mailing list