bug-gnulib
[Top][All Lists]
Advanced

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

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


From: roucaries . bastien
Subject: [PATCH 1/5] Use memset_s if possible for explicit_bzero
Date: Sat, 11 Apr 2020 23:20:31 +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 | 5 +++++
 2 files changed, 12 insertions(+)

diff --git a/lib/explicit_bzero.c b/lib/explicit_bzero.c
index 51b79a891..862855421 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..3ca5dc771 100644
--- a/m4/explicit_bzero.m4
+++ b/m4/explicit_bzero.m4
@@ -14,6 +14,11 @@ AC_DEFUN([gl_FUNC_EXPLICIT_BZERO],
   if test $ac_cv_func_explicit_bzero = no; then
     HAVE_EXPLICIT_BZERO=0
   fi
+
+  AC_CHECK_FUNCS_ONCE([memset_s])
+  if test $ac_cv_func_memset_s = no; then
+    HAVE_MEMSET_S=0
+  fi
 ])
 
 AC_DEFUN([gl_PREREQ_EXPLICIT_BZERO],
-- 
2.25.1




reply via email to

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