objective-c – Mac OS X相当于SecureZeroMemory / RtlSecureZeroMemory?

前端之家收集整理的这篇文章主要介绍了objective-c – Mac OS X相当于SecureZeroMemory / RtlSecureZeroMemory?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
是否有一个Mac OS X等效的 RtlSecureZeroMemory/ SecureZeroMemory,这是一个零内存块的功能,但是调用不会被编译器优化掉?

解决方法

写你自己的功能
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.”

原文链接:https://www.f2er.com/c/111011.html

猜你在找的C&C++相关文章