home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / unix / question / 16056 < prev    next >
Encoding:
Internet Message Format  |  1993-01-28  |  1.9 KB

  1. Xref: sparky comp.unix.questions:16056 comp.unix.programmer:6081
  2. Path: sparky!uunet!ukma!usenet.ins.cwru.edu!cleveland.Freenet.Edu!cq377
  3. From: cq377@cleveland.Freenet.Edu (David C. Williss)
  4. Newsgroups: comp.unix.questions,comp.unix.programmer
  5. Subject: Re: Segmentation fault in malloc()
  6. Date: 29 Jan 1993 03:55:20 GMT
  7. Organization: Case Western Reserve University, Cleveland, OH (USA)
  8. Lines: 37
  9. Message-ID: <1ka9r8INNcsf@usenet.INS.CWRU.Edu>
  10. References: <MfKP=4u00XQDMLWgAh@andrew.cmu.edu> <2515@itexjct.jct.ac.il>
  11. Reply-To: cq377@cleveland.Freenet.Edu (David C. Williss)
  12. NNTP-Posting-Host: hela.ins.cwru.edu
  13.  
  14.  
  15. In a previous article, tm8t+@andrew.cmu.edu (Tod McQuillin) says:
  16.  
  17. >jacobsen@itexjct.jct.ac.il (Joel Jacobsen) writes:
  18. >>  I wrote a program which use fgets to read a line from a file.
  19. >> one of the functions get a segmentation fault in the line:
  20. >> 
  21. >>     fgets(str,160,file);
  22. >> 
  23. >> when :  char *str;
  24. >>         FILE *file;
  25. >> 
  26. >> 
  27. >>  The frame stack in gdb show:
  28. >> 
  29. >>     (gdb) where
  30. >>     #0 0xf7734634 in malloc ()
  31. >>     #1 0xf7733bf0 in _findbuf ()
  32. >>     #2 0xf773b86c in _filbuf ()
  33. >>     #3 0xf773df40 in fgets ()
  34. >>     #4 0x2288 in choose_from_list () at m.c:81
  35. >> 
  36. >>  What might be the problem?
  37. >
  38. >Almost certainly you went past the end of one of the memory blocks
  39. >given to you by malloc, thus stomping on some pointers malloc uses
  40. >internally.  This is the first thing I check for when I get a segfault
  41. >in malloc(), and to date it has never been anything else.
  42. >
  43. I've had the same problem, with the same answer.  Darn hard to find
  44. too, as it'll never give a segmentation fault where you're clobbering
  45. it, just the next time you try to malloc.  
  46. -- 
  47.         -Dave Williss
  48. ---------------------------------------------------------------------------
  49. Standards are great!  Everybody should have one of their own!
  50. The opinions stated above are Mine!  All Mine!  You can't have them.
  51.