From 77a0e85d8d89bdb6d586323326a8fad1811e9524 Mon Sep 17 00:00:00 2001 From: rcombs Date: Fri, 6 Sep 2024 12:20:43 -0700 Subject: [PATCH] Use volatile stores in bytes destructor Ensures that the zeroization can never be optimized out. --- lib/bytes/include/bytes/bytes.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/bytes/include/bytes/bytes.h b/lib/bytes/include/bytes/bytes.h index 582701a2..7d18407e 100644 --- a/lib/bytes/include/bytes/bytes.h +++ b/lib/bytes/include/bytes/bytes.h @@ -17,7 +17,11 @@ struct bytes bytes& operator=(bytes&&) = default; // Zeroize on drop - ~bytes() { std::fill(_data.begin(), _data.end(), uint8_t(0)); } + ~bytes() + { + auto ptr = static_cast(_data.data()); + std::fill(ptr, ptr + _data.size(), uint8_t(0)); + } // Mimic std::vector ctors bytes(size_t count, const uint8_t& value = 0)