解决方法
写你自己的功能:
void secure_zero(void *s,size_t n) { volatile char *p = s; while (n--) *p++ = 0; }
编辑:在评论中的问题,为什么不memset?如果数组对象不被访问,则可以通过编译器优化掉memset函数调用.
请注意,C11添加(可选)功能memset_s和标准保证函数调用无法优化:
(C11,K.3.7.4.1p4) “[…] Unlike memset,any call to the memset_s function shall be evaluated strictly according to the rules of the abstract machine as described in (5.1.2.3). That is,any call to the memset_s function shall assume that the memory indicated by s and n may be accessible in the future and thus must contain the values indicated by c.”