delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/08/18/15:15:16

From: Jason Green <news AT jgreen4 DOT fsnet DOT co DOT uk>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Symify crash
Date: Fri, 18 Aug 2000 19:57:04 +0100
Organization: Customer of Energis Squared
Lines: 27
Message-ID: <m91rps83eoo8thnrmjumrbg1i9fhdlbf8a@4ax.com>
References: <3 DOT 0 DOT 5 DOT 32 DOT 20000813122244 DOT 007c0c00 AT pop DOT mail DOT yahoo DOT com> <3405-Sun13Aug2000163046+0300-eliz AT is DOT elta DOT co DOT il> <3996E3F4 DOT C9B37F8B AT softhome DOT net> <2593-Sun13Aug2000214525+0300-eliz AT is DOT elta DOT co DOT il> <fadqpscd8dj2q2la9jbojdvuou9a9283vl AT 4ax DOT com> <7704-Fri18Aug2000203741+0300-eliz AT is DOT elta DOT co DOT il>
NNTP-Posting-Host: modem-39.dorwinion.dialup.pol.co.uk
Mime-Version: 1.0
X-Trace: news5.svr.pol.co.uk 966625044 21108 62.136.157.167 (18 Aug 2000 18:57:24 GMT)
NNTP-Posting-Date: 18 Aug 2000 18:57:24 GMT
X-Complaints-To: abuse AT theplanet DOT net
X-Newsreader: Forte Agent 1.7/32.534
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

"Eli Zaretskii" <eliz AT is DOT elta DOT co DOT il> wrote:

> > I've no idea if this has anything to do with the problem discussed,
> > but the following code from syms.c lines 362-365 does indeed show some
> > data which is failing to be initialised:
> > 
> >   syms = (SymNode *)malloc(num_syms * sizeof(SymNode));
> >   memset(syms, num_syms * sizeof(SymNode), 0);
> >   files = (FileNode *)malloc(num_files * sizeof(FileNode));
> >   memset(files, num_files * sizeof(FileNode), 0);
> 
> I must be missing something, because I don't see what's not
> initialized here.  Care to point it out?

void *memset(void *buffer, int ch, size_t num);

The 2nd & 3rd arguments to memset are reversed.

Also, ISTR that generally accepted best practice is *not* to cast the
return from malloc() so the code should read:

syms = malloc(num_syms * sizeof(SymNode));
memset(syms, 0, num_syms * sizeof(SymNode));
files = malloc(num_files * sizeof(FileNode));
memset(files, 0, num_files * sizeof(FileNode));

Or use calloc().

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019