Always check malloc'ed memory?

后端 未结 10 875
滥情空心
滥情空心 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:43

    at the very least I would put an assert(ptr != NULL) in there so you get a meaningful error.

提交回复
热议问题