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