This is the mail archive of the libc-alpha@sourceware.cygnus.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: [A K KARTIK <akkartik@mailcity.com>] libc/1158: glibc: segmentation fault within malloc


> 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>

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]