From e0d79ee0320b337510aee5734579973597653df6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Tue, 24 Jan 2023 15:44:35 +0100 Subject: [PATCH] Modernize manual memzero implementation Instead of using volatile pointers to prevent the compiler from optimizing the call away, use a memory barrier. This requires support for embedded assembly, which should be fine after the recent requirement bumps. --- lib/defines.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/defines.h b/lib/defines.h index 54053103..d3416f11 100644 --- a/lib/defines.h +++ b/lib/defines.h @@ -54,10 +54,8 @@ #else /* !HAVE_MEMSET_S && HAVE_EXPLICIT_BZERO */ static inline void memzero(void *ptr, size_t size) { - volatile unsigned char * volatile p = ptr; - while (size--) { - *p++ = '\0'; - } + ptr = memset(ptr, '\0', size); + __asm__ __volatile__ ("" : : "r"(ptr) : "memory"); } #endif /* !HAVE_MEMSET_S && !HAVE_EXPLICIT_BZERO */