]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
Modernize manual memzero implementation
authorChristian Göttsche <cgzones@googlemail.com>
Tue, 24 Jan 2023 14:44:35 +0000 (15:44 +0100)
committerIker Pedrosa <ikerpedrosam@gmail.com>
Wed, 25 Jan 2023 10:07:25 +0000 (11:07 +0100)
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

index 54053103a9e1292c8e6030f55a89d549ad52227c..d3416f1193971a7c58f59ecbcb889603e5e5ae42 100644 (file)
 #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 */