Re: Debugging standard C library routines



achintmehta@xxxxxxxxx said:

The application/software that is being run, is messing up the memory
due to which a subsequent malloc fails.

Initialise every pointer. Check every malloc/calloc/realloc to ensure it
succeeded before you rely on its return value. Check that every array
access is within bounds (0 to n - 1, for an array of n elements). Set
indeterminate ('dangling') pointers to NULL.

Following these simple steps will get rid of 99.90072% of all known
memory-related crashes.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
.



Relevant Pages

  • Re: Pointer to Document in MDI application - Problem
    ... > initialise this pointer in my document's OnNewDocumentmethod, ... > longer pointing at a valid document, even though the default doc is ... >>calling the base class implmentation. ...
    (microsoft.public.vc.mfc)
  • Re: newbie troubles - creating an array dynamically. best practices.
    ... > dynamic array, I wrote a function, that has to do the job. ... It would allocate new memory, no pointers are being created in line A. You ... > in order to make it initialize the pointer c at one and the same address ... If you initialise pointer c, and then never assign to it again it will ...
    (comp.lang.cpp)
  • Re: Debugging standard C library routines
    ... I wouldn't go so far as to advise to initialise _every_ pointer. ... Such stupid advice leads, when followed, ... In Debug Mode, maybe. ...
    (comp.lang.c)
  • Re: NULL
    ... > What I do is When ever I declare a pointer, I Initialise with the NULL; ... zero value has the same meaning as with NULL. ...
    (alt.comp.lang.learn.c-cpp)
  • Re: NULL
    ... > What I do is When ever I declare a pointer, I Initialise with the NULL; ... > Then after this I Store the address of the Varible for which the Pointer ... When the pointer goes out of scope, there is no point in that. ...
    (alt.comp.lang.learn.c-cpp)