why do i get segmentation fault
Author Message
c0chensi Offline
Student


Reputation: 0
Post: #1
why do i get segmentation fault
my programs work fine on my some directories, but on some diretories i would get error msg saying
Segmentation fault (core dumped)
so what's going on?
(This post was last modified: 2012-11-02 22:59 by c0chensi.)
2012-11-02 22:58
Find all posts by this user Quote this message in a reply
c1lawsam Offline
Student


Reputation: 0
Post: #2
RE: why do i get segmentation fault
Segmentation fault is caused by roughly 2 million different scenarios, the most often being trying to call on memory that doesn't exist/isn't defined a la index out of bounds on an array, and trying to write on read-only memory (eg trying to concatenate strings without using a buffer).

Other than that, you're stuck trying to figure out your code line by line since the error messages are so minimalistic.
Debugging is kinda why people said its about 100 times slower to develop (but 100 times faster to run since it works directly with the memeory space instead of a virtual machine like java)

(2012-11-02 22:58)c0chensi Wrote:  my programs work fine on my some directories, but on some diretories i would get error msg saying
Segmentation fault (core dumped)
so what's going on?
2012-11-03 09:35
Find all posts by this user Quote this message in a reply
ajr Offline
Instructor


Reputation: 0
Post: #3
RE: why do i get segmentation fault
(2012-11-02 22:58)c0chensi Wrote:  my programs work fine on my some directories, but on some diretories i would get error msg saying
Segmentation fault (core dumped)
so what's going on?

Usually this is caused by dereferencing an invalid pointer value. Look for uses of a pointer variable without initializing it, or dereferencing a possibly-null pointer value.

(For example, this segfaulted for me on CDF just now, because that file name doesn't exist so fopen returned NULL, and getc dereferences the supplied pointer:
Code:
#include <stdio.h>

int main()
{
    FILE *fp = fopen("sladkfjlsdkfjlsadkfjdslakfj", "r");
    getc(fp);
    return(0);
}
)
2012-11-04 13:11
Find all posts by this user Quote this message in a reply
Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5


Forum Jump:


User(s) browsing this thread: 1 Guest(s)