Coming back to life after Segmentation Violation

前端 未结 13 2125
暗喜
暗喜 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:25

    Unfortunately, you can't in this case. The buggy function has undefined behavior and could have corrupted your program's state.

    What you CAN do is run the functions in a new process. If this process dies with a return code that indicates SIGSEGV, you know it has failed.

    You could also rewrite the functions yourself.

    0 讨论(0)
提交回复
热议问题