Skip to content

Commit

Permalink
Clean up logic in memory_cleanse() for MSVC
Browse files Browse the repository at this point in the history
Commit fbf327b ("Minimal code
changes to allow msvc compilation.") was indeed minimal in terms
of lines touched. But as a result of that minimalism it changed the
logic in memory_cleanse() to first call std::memset() and then
additionally the MSVC-specific SecureZeroMemory() function, and it
also moved a comment to the wrong location.

This commit removes the superfluous call to std::memset() on MSVC
and ensures that the comment is in the right position again.
  • Loading branch information
real-or-random committed Jun 6, 2019
1 parent 52ec4c6 commit cac30a4
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/support/cleanse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@
*/
void memory_cleanse(void *ptr, size_t len)
{
#if defined(_MSC_VER)
SecureZeroMemory(ptr, len);
#else
std::memset(ptr, 0, len);

/* As best as we can tell, this is sufficient to break any optimisations that
might try to eliminate "superfluous" memsets. If there's an easy way to
detect memset_s, it would be better to use that. */
#if defined(_MSC_VER)
SecureZeroMemory(ptr, len);
#else
__asm__ __volatile__("" : : "r"(ptr) : "memory");
#endif
}

0 comments on commit cac30a4

Please sign in to comment.