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.
This commit is contained in:
committed by
Iker Pedrosa
parent
90ead3cfb8
commit
e0d79ee032
@ -54,10 +54,8 @@
|
|||||||
#else /* !HAVE_MEMSET_S && HAVE_EXPLICIT_BZERO */
|
#else /* !HAVE_MEMSET_S && HAVE_EXPLICIT_BZERO */
|
||||||
static inline void memzero(void *ptr, size_t size)
|
static inline void memzero(void *ptr, size_t size)
|
||||||
{
|
{
|
||||||
volatile unsigned char * volatile p = ptr;
|
ptr = memset(ptr, '\0', size);
|
||||||
while (size--) {
|
__asm__ __volatile__ ("" : : "r"(ptr) : "memory");
|
||||||
*p++ = '\0';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endif /* !HAVE_MEMSET_S && !HAVE_EXPLICIT_BZERO */
|
#endif /* !HAVE_MEMSET_S && !HAVE_EXPLICIT_BZERO */
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user