What if malloc fails?

前端 未结 10 595
轮回少年
轮回少年 2020-12-09 08:57

If a malloc allocation fails, should we try it again?

In something like this:

char* mystrdup(const char *s)  
{
    char *ab = NULL;

           


        
10条回答
  •  北荒
    北荒 (楼主)
    2020-12-09 09:18

    No, never. If malloc returns NULL, that indicates an error, and you should probably abort.

提交回复
热议问题