mirror of
https://github.com/postgres/postgres.git
synced 2025-06-08 22:02:03 +03:00
Make our usage of memset_s() conform strictly to the C11 standard.
Per the letter of the C11 standard, one must #define __STDC_WANT_LIB_EXT1__ as 1 before including <string.h> in order to have access to memset_s(). It appears that many platforms are lenient about this, because we weren't doing it and yet the code appeared to work anyway. But we now find that with -std=c11, macOS is strict and doesn't declare memset_s, leading to compile failures since we try to use it anyway. (Given the lack of prior reports, perhaps this is new behavior in the latest SDK? No matter, we're clearly in the wrong.) In addition to the immediate problem, which could be fixed merely by adding the needed #define to explicit_bzero.c, it seems possible that our configure-time probe for memset_s() could fail in case a platform implements the function in some odd way due to this spec requirement. This concern can be fixed in largely the same way that we dealt with strchrnul() in 6da2ba1d8: switch to using a declaration-based configure probe instead of a does-it-link probe. Back-patch to v13 where we started using memset_s(). Reported-by: Lakshmi Narayana Velayudam <dev.narayana.v@gmail.com> Author: Tom Lane <tgl@sss.pgh.pa.us> Discussion: https://postgr.es/m/CAA4pTnLcKGG78xeOjiBr5yS7ZeE-Rh=FaFQQGOO=nPzA1L8yEA@mail.gmail.com Backpatch-through: 13
This commit is contained in:
parent
113351ee17
commit
00652b3c9f
15
configure
vendored
15
configure
vendored
@ -16310,7 +16310,7 @@ fi
|
|||||||
LIBS_including_readline="$LIBS"
|
LIBS_including_readline="$LIBS"
|
||||||
LIBS=`echo "$LIBS" | sed -e 's/-ledit//g' -e 's/-lreadline//g'`
|
LIBS=`echo "$LIBS" | sed -e 's/-ledit//g' -e 's/-lreadline//g'`
|
||||||
|
|
||||||
for ac_func in backtrace_symbols clock_gettime copyfile fdatasync getifaddrs getpeerucred getrlimit inet_pton kqueue mbstowcs_l memset_s poll posix_fallocate ppoll pstat pthread_is_threaded_np readlink readv setproctitle setproctitle_fast setsid shm_open strsignal symlink syncfs sync_file_range uselocale wcstombs_l writev
|
for ac_func in backtrace_symbols clock_gettime copyfile fdatasync getifaddrs getpeerucred getrlimit inet_pton kqueue mbstowcs_l poll posix_fallocate ppoll pstat pthread_is_threaded_np readlink readv setproctitle setproctitle_fast setsid shm_open strsignal symlink syncfs sync_file_range uselocale wcstombs_l writev
|
||||||
do :
|
do :
|
||||||
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
|
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
|
||||||
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
|
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
|
||||||
@ -16944,6 +16944,19 @@ cat >>confdefs.h <<_ACEOF
|
|||||||
#define HAVE_DECL_STRCHRNUL $ac_have_decl
|
#define HAVE_DECL_STRCHRNUL $ac_have_decl
|
||||||
_ACEOF
|
_ACEOF
|
||||||
|
|
||||||
|
ac_fn_c_check_decl "$LINENO" "memset_s" "ac_cv_have_decl_memset_s" "#define __STDC_WANT_LIB_EXT1__ 1
|
||||||
|
#include <string.h>
|
||||||
|
"
|
||||||
|
if test "x$ac_cv_have_decl_memset_s" = xyes; then :
|
||||||
|
ac_have_decl=1
|
||||||
|
else
|
||||||
|
ac_have_decl=0
|
||||||
|
fi
|
||||||
|
|
||||||
|
cat >>confdefs.h <<_ACEOF
|
||||||
|
#define HAVE_DECL_MEMSET_S $ac_have_decl
|
||||||
|
_ACEOF
|
||||||
|
|
||||||
|
|
||||||
# This is probably only present on macOS, but may as well check always
|
# This is probably only present on macOS, but may as well check always
|
||||||
ac_fn_c_check_decl "$LINENO" "F_FULLFSYNC" "ac_cv_have_decl_F_FULLFSYNC" "#include <fcntl.h>
|
ac_fn_c_check_decl "$LINENO" "F_FULLFSYNC" "ac_cv_have_decl_F_FULLFSYNC" "#include <fcntl.h>
|
||||||
|
@ -1843,7 +1843,6 @@ AC_CHECK_FUNCS(m4_normalize([
|
|||||||
inet_pton
|
inet_pton
|
||||||
kqueue
|
kqueue
|
||||||
mbstowcs_l
|
mbstowcs_l
|
||||||
memset_s
|
|
||||||
poll
|
poll
|
||||||
posix_fallocate
|
posix_fallocate
|
||||||
ppoll
|
ppoll
|
||||||
@ -1924,6 +1923,8 @@ AC_CHECK_DECLS([strlcat, strlcpy, strnlen])
|
|||||||
AC_CHECK_DECLS([preadv], [], [AC_LIBOBJ(preadv)], [#include <sys/uio.h>])
|
AC_CHECK_DECLS([preadv], [], [AC_LIBOBJ(preadv)], [#include <sys/uio.h>])
|
||||||
AC_CHECK_DECLS([pwritev], [], [AC_LIBOBJ(pwritev)], [#include <sys/uio.h>])
|
AC_CHECK_DECLS([pwritev], [], [AC_LIBOBJ(pwritev)], [#include <sys/uio.h>])
|
||||||
AC_CHECK_DECLS([strchrnul], [], [], [#include <string.h>])
|
AC_CHECK_DECLS([strchrnul], [], [], [#include <string.h>])
|
||||||
|
AC_CHECK_DECLS([memset_s], [], [], [#define __STDC_WANT_LIB_EXT1__ 1
|
||||||
|
#include <string.h>])
|
||||||
|
|
||||||
# This is probably only present on macOS, but may as well check always
|
# This is probably only present on macOS, but may as well check always
|
||||||
AC_CHECK_DECLS(F_FULLFSYNC, [], [], [#include <fcntl.h>])
|
AC_CHECK_DECLS(F_FULLFSYNC, [], [], [#include <fcntl.h>])
|
||||||
|
@ -126,6 +126,10 @@
|
|||||||
to 0 if you don't. */
|
to 0 if you don't. */
|
||||||
#undef HAVE_DECL_LLVMORCGETSYMBOLADDRESSIN
|
#undef HAVE_DECL_LLVMORCGETSYMBOLADDRESSIN
|
||||||
|
|
||||||
|
/* Define to 1 if you have the declaration of `memset_s', and to 0 if you
|
||||||
|
don't. */
|
||||||
|
#undef HAVE_DECL_MEMSET_S
|
||||||
|
|
||||||
/* Define to 1 if you have the declaration of `posix_fadvise', and to 0 if you
|
/* Define to 1 if you have the declaration of `posix_fadvise', and to 0 if you
|
||||||
don't. */
|
don't. */
|
||||||
#undef HAVE_DECL_POSIX_FADVISE
|
#undef HAVE_DECL_POSIX_FADVISE
|
||||||
@ -383,9 +387,6 @@
|
|||||||
/* Define to 1 if you have the <memory.h> header file. */
|
/* Define to 1 if you have the <memory.h> header file. */
|
||||||
#undef HAVE_MEMORY_H
|
#undef HAVE_MEMORY_H
|
||||||
|
|
||||||
/* Define to 1 if you have the `memset_s' function. */
|
|
||||||
#undef HAVE_MEMSET_S
|
|
||||||
|
|
||||||
/* Define to 1 if the system has the type `MINIDUMP_TYPE'. */
|
/* Define to 1 if the system has the type `MINIDUMP_TYPE'. */
|
||||||
#undef HAVE_MINIDUMP_TYPE
|
#undef HAVE_MINIDUMP_TYPE
|
||||||
|
|
||||||
|
@ -12,9 +12,11 @@
|
|||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#define __STDC_WANT_LIB_EXT1__ 1 /* needed to access memset_s() */
|
||||||
|
|
||||||
#include "c.h"
|
#include "c.h"
|
||||||
|
|
||||||
#if defined(HAVE_MEMSET_S)
|
#if HAVE_DECL_MEMSET_S
|
||||||
|
|
||||||
void
|
void
|
||||||
explicit_bzero(void *buf, size_t len)
|
explicit_bzero(void *buf, size_t len)
|
||||||
|
@ -240,6 +240,7 @@ sub GenerateFiles
|
|||||||
HAVE_DECL_LLVMGETHOSTCPUNAME => 0,
|
HAVE_DECL_LLVMGETHOSTCPUNAME => 0,
|
||||||
HAVE_DECL_LLVMGETHOSTCPUFEATURES => 0,
|
HAVE_DECL_LLVMGETHOSTCPUFEATURES => 0,
|
||||||
HAVE_DECL_LLVMORCGETSYMBOLADDRESSIN => 0,
|
HAVE_DECL_LLVMORCGETSYMBOLADDRESSIN => 0,
|
||||||
|
HAVE_DECL_MEMSET_S => 0,
|
||||||
HAVE_DECL_POSIX_FADVISE => 0,
|
HAVE_DECL_POSIX_FADVISE => 0,
|
||||||
HAVE_DECL_PREADV => 0,
|
HAVE_DECL_PREADV => 0,
|
||||||
HAVE_DECL_PWRITEV => 0,
|
HAVE_DECL_PWRITEV => 0,
|
||||||
@ -321,7 +322,6 @@ sub GenerateFiles
|
|||||||
HAVE_MBARRIER_H => undef,
|
HAVE_MBARRIER_H => undef,
|
||||||
HAVE_MBSTOWCS_L => 1,
|
HAVE_MBSTOWCS_L => 1,
|
||||||
HAVE_MEMORY_H => 1,
|
HAVE_MEMORY_H => 1,
|
||||||
HAVE_MEMSET_S => undef,
|
|
||||||
HAVE_MINIDUMP_TYPE => 1,
|
HAVE_MINIDUMP_TYPE => 1,
|
||||||
HAVE_MKDTEMP => undef,
|
HAVE_MKDTEMP => undef,
|
||||||
HAVE_NETINET_TCP_H => undef,
|
HAVE_NETINET_TCP_H => undef,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user