Thread: Cause of a seg fault (core dumped)

  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    84

    Thumbs down Cause of a seg fault (core dumped)

    Im running a program that takes several days to run and think I know the cause... I didnt run it in gdb so I have no idea exactly besides a hint at where it is. Is this a possible cause?

    Looking back, I foolish, tried to open and then write to an illegal memory location (i think at least). The situation being that I opened a file in a directory that doesn't exist to then write in it. Could that be the cause -- since it wasn't a created directory?

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Are you actually not checking whether your fopen (or equivalent) call didn't succeed? Really? Yes writing to a file handle that isn't open can do bad things.

  3. #3
    Registered User
    Join Date
    Feb 2010
    Posts
    84
    Quote Originally Posted by tabstop View Post
    Are you actually not checking whether your fopen (or equivalent) call didn't succeed? Really? Yes writing to a file handle that isn't open can do bad things.
    Yes... That's one of the reasons I said foolish :P...

    Ughh...

    Check with:
    if(file == NULL) printf("fail");

    ?

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    file will be NULL if it didn't open, that's correct. And you'll want to do more than just print "fail" -- find a proper file, or give it up and abort. If your program has already been running for days and days, the first is obviously more appealing.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 06-05-2010, 02:58 AM
  2. Segmentation fault, core dumped
    By dweenigma in forum C Programming
    Replies: 2
    Last Post: 05-21-2007, 03:50 PM
  3. Runtime error 'segmentation fault (core dumped)'
    By mikemccready in forum C Programming
    Replies: 2
    Last Post: 03-17-2003, 07:14 AM
  4. Segmantation Fault (core dumped) error
    By Vinnie66 in forum C Programming
    Replies: 6
    Last Post: 03-25-2002, 01:34 PM
  5. Segmentation fault (core dumped)
    By JYSN in forum C Programming
    Replies: 1
    Last Post: 02-21-2002, 03:24 AM