3 ms·
A good solution in c is to use calloc, which is malloc + zero'ing out the memory. http://www.cplusplus.com/reference/clibrary/cstdlib/calloc/ http://www.cplusp
by sn 14y ago
A good solution in c is to use calloc, which is malloc + zero'ing out the memory.
http://www.cplusplus.com/reference/clibrary/cstdlib/calloc/ http://www.cplusplus.com/reference/clibrary/cstdlib/calloc/
Also, in a standards-compliant compiler, statically declared variables are automatically initialized to zero unless stated otherwise.
- Someone 14y agoThat won't work here. Here, the goal is to have 'cfree': zero'ing out memory and then freeing it.
- sn 14y agoOK, shows me for skimming too much. There apparently used to be a cfree though it appears to be equivalent to free. I upvoted rwg's comment regarding CERT's Secure Coding wiki. memset_s is the correct solution given it is part of the C11 standard.