简体   繁体   English

为什么在违反运行时约束的情况下 memcpy_s 会归零?

[英]Why does memcpy_s zeroize in the case of runtime constraint violation?

In this implementation of memcpy_s ( as well as others ) the region pointed to by dest is zeroized when a runtime constraint violation occurs.memcpy_s以及其他)的这个实现中,当发生运行时约束违规时, dest指向的区域被归零。

Can anyone explain why is this done?谁能解释为什么这样做? I got footguned by this a few days back and I would be interested in knowing why this is done.几天前我对此感到震惊,我很想知道为什么会这样做。

This behavior is documented in section K.3.7.1.1 of the C standard as well as the Microsoft documentation .此行为记录在C 标准的第 K.3.7.1.1 节以及Microsoft 文档中。

The reason for this most likely is to have deterministic behavior in the failure case so that you don't end up with dest containing uninitialized values.这样做的原因很可能是在失败情况下具有确定性行为,因此您最终不会得到包含未初始化值的dest This allows for more robust testability.这允许更强大的可测试性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM