Always check malloc'ed memory?

后端 未结 10 927
滥情空心
滥情空心 2020-12-09 03:05

I often catch myself doing the following (in non-critical components):

some_small_struct *ptr=(some_small_struct *) malloc(sizeof(some_small_struct));
ptr-&g         


        
10条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-09 03:58

    Yes, having insufficient memeory will almost certatinly presage other failures coming soon. But how sure are you that no corrupt output will occur between the failure to allocate and the final crash?

    How sure are you for every program, every time you make an edit.

    Catch your errors so you can know you crashed on time.

提交回复
热议问题