Xref: utzoo comp.lang.c:16400 comp.unix.wizards:14800 Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ncar!ames!amelia!msf From: msf@amelia.nas.nasa.gov (Michael S. Fischbein) Newsgroups: comp.lang.c,comp.unix.wizards Subject: malloc/stack conflicts Keywords: dynamic memory, recursion Message-ID: <1499@amelia.nas.nasa.gov> Date: 21 Feb 89 21:39:55 GMT Distribution: usa Lines: 37 I have a program I am working on that passes an argv-like list of arguments to itself recursively. It mallocs memory to deal with the intermediate structures. I am at a point where the pointer returned by malloc with the correct size requested overlaps the parameter for the current invocation. Does anyone have any suggestions on where I can look to fix this? More succinctly, I have a routine void foo(i, list, j) int i; char *list[]; int j; { struct bar *abar; abar = (struct bar *) malloc((unsigned) (j-i)*sizeof(struct bar)); /* stuff that gets each string from list and constructs the correct * struct bar */ /* etc */ } where the abar returned by malloc is such that the list parameter is trashed after the first couple of calls (it is fine on invocation, both by printfs and dbx). If I duplicate the malloc line, that is, allocate double the memory I need and start in the second half, the routine works fine. This is on a Sun 3/60 under SunOS 3.4. Does anyone know where I should look? mike -- Michael Fischbein msf@prandtl.nas.nasa.gov ...!seismo!decuac!csmunix!icase!msf These are my opinions and not necessarily official views of any organization.