Bus error vs Segmentation fault

前端 未结 7 767
梦毁少年i
梦毁少年i 2020-12-24 01:19

Difference between a bus error and a segmentation fault? Can it happen that a program gives a seg fault and stops for the first time and for the second time it may give a bu

7条回答
  •  情话喂你
    2020-12-24 02:10

    Interpreting your question (possibly incorrectly) as meaning "I am intermittently getting a SIGSEGV or a SIGBUS, why isn't it consistent?", it's worth noting that doing dodgy things with pointers is not guaranteed by the C or C++ standards to result in a segfault; it's just "undefined behaviour", which as a professor I had once put it means that it may instead cause crocodiles to emerge from the floorboards and eat you.

    So your situation could be that you have two bugs, where the first to occur sometimes causes SIGSEGV, and the second (if the segfault didn't happen and the program is still running) causes a SIGBUS.

    I recommend you step through with a debugger, and look out for crocodiles.

提交回复
热议问题