From 818572b398a9454e0edc1bb7f7135fc6af244694 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bastien=20Roucari=C3=A8s?= Date: Mon, 13 Apr 2020 01:09:14 +0200 Subject: [PATCH] explicit_bzero: Use memset_s() when available. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Some OS define memset_s instead of explicit_bzero. Use it. * lib/explicit_bzero.c (__STDC_WANT_LIB_EXT1__): Define. (explicit_bzero): Use memset_s when available. * m4/explicit_bzero.m4 (gl_PREREQ_EXPLICIT_BZERO): Test for memset_s. Signed-off-by: Bastien Roucariès --- ChangeLog | 7 +++++++ lib/explicit_bzero.c | 7 +++++++ m4/explicit_bzero.m4 | 1 + 3 files changed, 15 insertions(+) diff --git a/ChangeLog b/ChangeLog index 90fb563123..8bb1465d82 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2020-04-13 Bastien Roucariès + + explicit_bzero: Use memset_s() when available. + * lib/explicit_bzero.c (__STDC_WANT_LIB_EXT1__): Define. + (explicit_bzero): Use memset_s when available. + * m4/explicit_bzero.m4 (gl_PREREQ_EXPLICIT_BZERO): Test for memset_s. + 2020-04-13 Bastien Roucariès explicit_bzero tests: Fix test failure on OpenBSD 6.5. diff --git a/lib/explicit_bzero.c b/lib/explicit_bzero.c index 51b79a8918..2168a52854 100644 --- a/lib/explicit_bzero.c +++ b/lib/explicit_bzero.c @@ -25,6 +25,11 @@ # include #endif +/* memset_s need this define */ +#if HAVE_MEMSET_S +# define __STDC_WANT_LIB_EXT1__ 1 +#endif + #include #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 507816affd..a415e7b4f5 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.39.5