How to debug segmentation fault?

前端 未结 4 1117
我在风中等你
我在风中等你 2020-12-16 08:33

It works when, in the loop, I set every element to 0 or to entry_count-1. It works when I set it up so that entry_count is small, and I write it by hand instead of by loop (

4条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-16 09:03

    That is hard, I used valgrind tools to debug seg-faults and it usually pointed to violations.

    Likely your problem is freed memory that you are writing to i.e. sorted_array gets out of scope or gets freed. Adding more code hides this problem as data allocation shifts around.

提交回复
热议问题