Segmentation Fault

17 篇文章 0 订阅
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.


 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值