bug-gnulib
[Top][All Lists]
Advanced

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

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


From: Bastien ROUCARIES
Subject: Re: [PATCH 1/5] Use memset_s if possible for explicit_bzero
Date: Sun, 12 Apr 2020 00:18:13 +0200

Ok, I will do that.

On Sun, Apr 12, 2020 at 12:13 AM Bruno Haible <address@hidden> wrote:
>
> Hello Bastien,
>
> Allow me a couple of comments, to make you more familiar with gnulib
> coding conventions.
>
> > Some OS define memset_s instead of explicit_bzero. Use it.
>
> Indeed, FreeBSD 12 and Solaris 11.4 provide 'memset_s'.
>
> > --- 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
>
> We prefer to write it as
>
>    # define __STDC_WANT_LIB_EXT1__ 1
>
> in order to highlight the number of outer #if levels.
>
> > @@ -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);
>
> Please, can you insert spaces before the opening paren and after the
> commas - to go with common GNU style?
>
> > 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
>
> You don't need the autoconf/shell variable HAVE_MEMSET_S (only the
> preprocessor symbol HAVE_MEMSET_S). Therefore no need to set
> HAVE_MEMSET_S=0.
>
> The remaining added code, AC_CHECK_FUNCS_ONCE([memset_s]),
> is only needed for the compilation of explicit_bzero.c - not
> in other *.m4 files or in the module descriptions. By convention,
> we put such code into the gl_PREREQ_EXPLICIT_BZERO macro.
>
> Bruno
>



reply via email to

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