Re: Debugging standard C library routines
- From: Frederick Gotham <fgothamNO@xxxxxxxx>
- Date: Sun, 01 Oct 2006 13:19:51 GMT
Richard Heathfield posted:
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.
I wouldn't go so far as to advise to initialise _every_ pointer.
#define POVER(arr) ((arr) + sizeof(arr)/sizeof*(arr))
int *p;
for(p=array1;POVER(array1)!=p;++p) /* Something */ ;
for(p=array2;POVER(array2)!=p;++p) /* Something */ ;
Check every malloc/calloc/realloc to ensure it succeeded before you rely
on its return value.
If malloc'ing less than a kilobyte, I wouldn't bother.
Check that every array access is within bounds (0 to n - 1, for an array
of n elements).
One should _always_ watch out for such things when looking back over one's
code.
Set indeterminate ('dangling') pointers to NULL.
In Debug Mode, maybe. It wastes valuable nanoseconds (if not microseconds)
in Release Mode. Maybe something like the following would be a compromise:
#ifdef NDEBUG
#define DMODE(statement)
#else
#define DMODE(statement) statement
#endif
int main()
{
int *p;
...
free(p); DMODE(p=0);
}
--
Frederick Gotham
.
- Follow-Ups:
- Re: Debugging standard C library routines
- From: Old Wolf
- Re: Debugging standard C library routines
- From: Keith Thompson
- Re: Debugging standard C library routines
- From: Richard Bos
- Re: Debugging standard C library routines
- From: CBFalconer
- Re: Debugging standard C library routines
- From: sjdevnull@xxxxxxxxx
- Re: Debugging standard C library routines
- From: jacob navia
- Re: Debugging standard C library routines
- From: Eric Sosman
- Re: Debugging standard C library routines
- From: Richard Heathfield
- Re: Debugging standard C library routines
- References:
- Debugging standard C library routines
- From: achintmehta
- Re: Debugging standard C library routines
- From: Richard Heathfield
- Debugging standard C library routines
- Prev by Date: Re: ow can i use fgets to read and ignore the first two lines of a file and output into another file
- Next by Date: Re: Help with code (parse error)
- Previous by thread: Re: Debugging standard C library routines
- Next by thread: Re: Debugging standard C library routines
- Index(es):
Relevant Pages
|