Path: utzoo!mnetor!uunet!husc6!rutgers!columbia!read.columbia.edu!kearns From: kearns@read.columbia.edu (Steve Kearns) Newsgroups: comp.sys.mac Subject: LSC Storage bugs Message-ID: <5295@columbia.edu> Date: 7 Feb 88 21:45:00 GMT Sender: nobody@columbia.edu Reply-To: kearns@cs.columbia.edu Organization: Columbia University Department of Computer Science Lines: 29 Keywords: LSC, malloc, bugs In debugging a program of mine, I discovered that LightSpeed C has several serious problems with the memory management routines. Specifically: (*) Their malloc routine calls NewPtr, but passes an int instead of a long. Since this routine seems to work, there is probably a "feature" of the glue routines that make this a non-problem in practice. (*) The realloc routine does not try hard enough. Realloc shrinks or expands a block of memory. According to the unix definition of realloc (and the description in lSC), realloc can actually return a pointer to a new area of memory, as long as it copies the relevant contents of the old block over. This is often neccessary if the block of memory is expanding. However, the LSC realloc routine calls SetPtrSize, a toolbox routine which doesn't consider moving it if it is unable to grow. Therefore, realloc fails much more often then neccessary. (*) the free routine just calls the cfree routine, when it should actually return the value of the cfree routine. LSC is a great product; I have noticed, though, that in most compilers the libraries are an afterthought, often delegated to inexperienced programmers. Especially with memory management routines this is bad. (I found even worse problems in Aztec C's memory management, for example, several years ago) If anyone needs the code that fixes this I will be glad to supply it, although with the above description it should be easy to fix. -steve