malloc 0

 

buf = malloc(0)     //buf为一个有效的地址

buf = malloc(1.5)     //buf为一个有效的地址

buf = malloc(-1)     //buf为NULL

free(NULL)       //编译不会报错,运行也没问题,不清楚是否存在影响
例如:
char *buf = NULL;
buf = malloc(4);
memset(buf,0,4);
free(buf)
buf = NULL;
free(buf);

posted @ 2018-02-07 16:28  _小百  阅读(153)  评论(0编辑  收藏  举报