bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 1/6] Use memset_s if possible for explicit_bzero


From: roucaries . bastien
Subject: [PATCH 1/6] Use memset_s if possible for explicit_bzero
Date: Sun, 12 Apr 2020 02:48:22 +0200

From: Bastien Roucariès <address@hidden>

Some OS define memset_s instead of explicit_bzero. Use it.

Signed-off-by: Bastien Roucariès <address@hidden>
---
 lib/explicit_bzero.c | 7 +++++++
 m4/explicit_bzero.m4 | 1 +
 2 files changed, 8 insertions(+)

diff --git a/lib/explicit_bzero.c b/lib/explicit_bzero.c
index 51b79a891..2168a5285 100644
--- a/lib/explicit_bzero.c
+++ b/lib/explicit_bzero.c
@@ -25,6 +25,11 @@
 # include <config.h>
 #endif
 
+/* memset_s need this define */
+#if HAVE_MEMSET_S
+# define __STDC_WANT_LIB_EXT1__ 1
+#endif
+
 #include <string.h>
 
 #if _LIBC
@@ -40,6 +45,8 @@ explicit_bzero (void *s, size_t len)
 {
 #ifdef HAVE_EXPLICIT_MEMSET
   explicit_memset (s, 0, len);
+#elif HAVE_MEMSET_S
+  (void) memset_s (s, len, '\0', len);
 #else
   memset (s, '\0', len);
 # if defined __GNUC__ && !defined __clang__
diff --git a/m4/explicit_bzero.m4 b/m4/explicit_bzero.m4
index 507816aff..a415e7b4f 100644
--- a/m4/explicit_bzero.m4
+++ b/m4/explicit_bzero.m4
@@ -19,4 +19,5 @@ AC_DEFUN([gl_FUNC_EXPLICIT_BZERO],
 AC_DEFUN([gl_PREREQ_EXPLICIT_BZERO],
 [
   AC_CHECK_FUNCS([explicit_memset])
+  AC_CHECK_FUNCS_ONCE([memset_s])
 ])
-- 
2.25.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]