您的位置:首页 > 其它

Segmentation Fault

2007-06-02 00:47 274 查看
An error in which a running Unix program attempts to access memory not allocated to it and terminates with a segmentation violation error and usually a core dump.

Segmentation Fault occurred when running c program that is reading or writing non-exist segment(physical memory space). Example, declare an array of int x[5] and you try putting or reading 6th item(s) that the cpu system to crash.

It can be a sporadic occurance; for example, in the program below, if you type 'Dragon' it works quite happily. It's overwriting some part of the memory with something it shouldn't be. But it doesn't segfault until you get to something like 'Dragon Dave is overwriting your memory!'. This is a buffer overrun, and that's *bad*, and a very, very large hole in your programs security.

#include "stdio.h"
int main()
{
/* allocate 5 bytes for the string */
char name[5];
/* enter a string - possibly much longer */
gets(name);
/* display the string */
printf("Hello, %s.",name);
}

segmentation faults may also occur in case of hardware errors, f.e. hard-disk or Memory failure. to find out, try running memtest86 and/or any hard-disk diagnostic tools from the manufacturer

segmentation fault is a type of error which occurs when u try to access a non existant physical memory address. Sometimes during execution of a C program u freed memory and then within the scope of the same program try again to use the same memory, then also the seg. fault occurs, this is due to the fact that untill the completion of the program the memory utilised is not returned to the operating system.

This is often caused by improper usage of pointers in the source code, dereferencing a null pointer, or (in C) inadvertently using a non-pointer variable as a pointer.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: