How to zero out new memory after realloc

前端 未结 4 1093
闹比i
闹比i 2020-12-06 10:53

What is the best way to zero out new memory after calling realloc while keeping the initially allocated memory intact?

#include 
#include <         


        
4条回答
  •  醉梦人生
    2020-12-06 11:46

    First of all, realloc can fail, so you need to check for NULL. Second, there is no better way to zero out the memory: just memset from the end of the old buffer to the end of the larger buffer.

提交回复
热议问题