Coming back to life after Segmentation Violation

前端 未结 13 2164
暗喜
暗喜 2020-12-08 11:26

Is it possible to restore the normal execution flow of a C program, after the Segmentation Fault error?

struct A {
    int x;
};
A* a = 0;

a->x = 123; /         


        
13条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-08 12:10

    Call this, and when a segfault will occur, your code will execute segv_handler and then continue back to where it was.

    void segv_handler(int)
    {
      // Do what you want here
    }
    
    signal(SIGSEGV, segv_handler);
    

提交回复
热议问题