What causes a SIGSEGV

后端 未结 7 942
野性不改
野性不改 2020-11-27 15:52

I need to know the root cause of the segmentation fault (SIGSEGV), and how to handle it.

7条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-27 16:31

    There are various causes of segmentation faults, but fundamentally, you are accessing memory incorrectly. This could be caused by dereferencing a null pointer, or by trying to modify readonly memory, or by using a pointer to somewhere that is not mapped into the memory space of your process (that probably means you are trying to use a number as a pointer, or you incremented a pointer too far). On some machines, it is possible for a misaligned access via a pointer to cause the problem too - if you have an odd address and try to read an even number of bytes from it, for example (that can generate SIGBUS, instead).

提交回复
热议问题