+2024-11-06 Bruno Haible <bruno@clisp.org>
+
+ memset_explicit: Guarantee N3322 functionality.
+ * m4/memset_explicit.m4 (gl_PREREQ_MEMSET_EXPLICIT): Require
+ AC_CANONICAL_HOST. Test whether memset_s supports zero-length
+ operations.
+ * lib/memset_explicit.c (memset_explicit): Don't invoke memset_s with
+ argument 0 if memset_s does not support this.
+
2024-11-06 Bruno Haible <bruno@clisp.org>
wcsncat: Fix configure test.
#if HAVE_EXPLICIT_MEMSET
return explicit_memset (s, c, len);
#elif HAVE_MEMSET_S
- (void) memset_s (s, len, c, len);
+# if !HAVE_MEMSET_S_SUPPORTS_ZERO
+ if (len > 0)
+# endif
+ (void) memset_s (s, len, c, len);
return s;
#elif defined __GNUC__ && !defined __clang__
memset (s, c, len);
# memset_explicit.m4
-# serial 3
+# serial 4
dnl Copyright 2022-2024 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
AC_DEFUN([gl_PREREQ_MEMSET_EXPLICIT],
[
+ AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
AC_CHECK_FUNCS([explicit_memset])
AC_CHECK_FUNCS_ONCE([memset_s])
+ if test $ac_cv_func_memset_s = yes; then
+ AC_CACHE_CHECK([for working memset_s],
+ [gl_cv_func_memset_s_works],
+ [AC_RUN_IFELSE(
+ [AC_LANG_PROGRAM(
+ [[#include <string.h>
+ #include <stddef.h>
+ ]], [[
+ (void) memset_s (NULL, 0, '?', 0);
+ ]])
+ ],
+ [gl_cv_func_memset_s_works=yes],
+ [gl_cv_func_memset_s_works=no],
+ [case "$host_os" in
+ # Guess no on Solaris.
+ solaris*)
+ gl_cv_func_memset_s_works="guessing no" ;;
+ *)
+ gl_cv_func_memset_s_works="guessing yes" ;;
+ esac
+ ])
+ ])
+ case "$gl_cv_func_memset_s_works" in
+ *yes)
+ AC_DEFINE([HAVE_MEMSET_S_SUPPORTS_ZERO], [1],
+ [Define to 1 if memset_s support zero-length operations.])
+ ;;
+ esac
+ fi
])