Article View: gnu.utils.bug
Article #1658unportable use of malloc in ld.c
From: Peter R. Ham
Date: Tue, 06 Jun 1989 16:58
Date: Tue, 06 Jun 1989 16:58
64 lines
1935 bytes
1935 bytes
I don't have a version number for this code, but the last date in the
ChangeLog is:
Thu Dec 29 01:48:03 1988 Richard Stallman (rms at sugar-bombs.ai.mit.edu)
The following code implicity assumes that xmalloc() returns zeroed memory:
main()
...
cmdline_references =
(struct glosym **) xmalloc (cl_refs_allocated
* sizeof(struct glosym *));
It's my understanding that "malloc()", which "xmalloc()" calls is not
guarranteed return a pointer to zero filled memory.
This dependecny can be fixed by clearing the memory with bzero inside xmalloc()
or appending:
bzero((char *) cmdline_references, cl_refs_allocated *
sizeof(struct glosym *));
After the call to xmalloc.
Later on, this assumption is used:
void
add_cmdline_ref (sp)
struct glosym *sp;
{
struct glosym **ptr;
for (ptr = cmdline_references;
ptr < cmdline_references + cl_refs_allocated && *ptr;(RIGHT HERE!!!)
ptr++)
;
if (ptr == cmdline_references + cl_refs_allocated)
{
int diff = ptr - cmdline_references;
cl_refs_allocated *= 2;
cmdline_references = (struct glosym **)
xrealloc (cmdline_references,
cl_refs_allocated * sizeof (struct glosym *));
ptr = cmdline_references + diff;
}
*ptr++ = sp;
*ptr = (struct glosym *) 0;
}
and there is similar code in "do_warnings()".
--
Peter Ham PO Box 3430 (415) 324-4782
MS Computer Science Student Stanford, CA ham@polya.stanford.edu
Stanford University 94309
Technical Details
Message-ID:
<HAM.89Jun6095844@polya.Stanford.EDU>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!sun-barr!decwrl!shelby!polya!hamShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!sun-barr!decwrl!shelby!polya!ham From: ham@polya.Stanford.EDU (Peter R. Ham) Newsgroups: gnu.utils.bug Subject: unportable use of malloc in ld.c Message-ID: <HAM.89Jun6095844@polya.Stanford.EDU> Date: 6 Jun 89 16:58:44 GMT Sender: Peter R. Ham <ham@polya.Stanford.EDU> Distribution: gnu Organization: Stanford University Lines: 64