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

Viewed 40

In this implementation of memcpy_s (as well as others) the region pointed to by dest is zeroized when a runtime constraint violation occurs.

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.

1 Answers

This behavior is documented in section K.3.7.1.1 of the C standard as well as the Microsoft documentation.

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. This allows for more robust testability.

Related