Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit00652b3

Browse files
committed
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 tohave access to memset_s(). It appears that many platforms are lenientabout this, because we weren't doing it and yet the code appeared towork anyway. But we now find that with -std=c11, macOS is strict anddoesn't declare memset_s, leading to compile failures since we try touse it anyway. (Given the lack of prior reports, perhaps this is newbehavior in the latest SDK? No matter, we're clearly in the wrong.)In addition to the immediate problem, which could be fixed merely byadding the needed #define to explicit_bzero.c, it seems possible thatour configure-time probe for memset_s() could fail in case a platformimplements the function in some odd way due to this spec requirement.This concern can be fixed in largely the same way that we dealt withstrchrnul() in6da2ba1: switch to using a declaration-basedconfigure 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.comBackpatch-through: 13
1 parent113351e commit00652b3

File tree

5 files changed

+24
-7
lines changed

5 files changed

+24
-7
lines changed

‎configure

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16310,7 +16310,7 @@ fi
1631016310
LIBS_including_readline="$LIBS"
1631116311
LIBS=`echo "$LIBS" | sed -e 's/-ledit//g' -e 's/-lreadline//g'`
1631216312

16313-
for ac_func in backtrace_symbols clock_gettime copyfile fdatasync getifaddrs getpeerucred getrlimit inet_pton kqueue mbstowcs_lmemset_spoll 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
16313+
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
1631416314
do :
1631516315
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
1631616316
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
@@ -16944,6 +16944,19 @@ cat >>confdefs.h <<_ACEOF
1694416944
#define HAVE_DECL_STRCHRNUL $ac_have_decl
1694516945
_ACEOF
1694616946

16947+
ac_fn_c_check_decl "$LINENO" "memset_s" "ac_cv_have_decl_memset_s" "#define __STDC_WANT_LIB_EXT1__ 1
16948+
#include <string.h>
16949+
"
16950+
if test "x$ac_cv_have_decl_memset_s" = xyes; then :
16951+
ac_have_decl=1
16952+
else
16953+
ac_have_decl=0
16954+
fi
16955+
16956+
cat >>confdefs.h <<_ACEOF
16957+
#define HAVE_DECL_MEMSET_S $ac_have_decl
16958+
_ACEOF
16959+
1694716960

1694816961
# This is probably only present on macOS, but may as well check always
1694916962
ac_fn_c_check_decl "$LINENO" "F_FULLFSYNC" "ac_cv_have_decl_F_FULLFSYNC" "#include <fcntl.h>

‎configure.ac

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1843,7 +1843,6 @@ AC_CHECK_FUNCS(m4_normalize([
18431843
inet_pton
18441844
kqueue
18451845
mbstowcs_l
1846-
memset_s
18471846
poll
18481847
posix_fallocate
18491848
ppoll
@@ -1924,6 +1923,8 @@ AC_CHECK_DECLS([strlcat, strlcpy, strnlen])
19241923
AC_CHECK_DECLS([preadv],[],[AC_LIBOBJ(preadv)],[#include <sys/uio.h>])
19251924
AC_CHECK_DECLS([pwritev],[],[AC_LIBOBJ(pwritev)],[#include <sys/uio.h>])
19261925
AC_CHECK_DECLS([strchrnul],[],[],[#include <string.h>])
1926+
AC_CHECK_DECLS([memset_s],[],[],[#define __STDC_WANT_LIB_EXT1__ 1
1927+
#include <string.h>])
19271928

19281929
# This is probably only present on macOS, but may as well check always
19291930
AC_CHECK_DECLS(F_FULLFSYNC,[],[],[#include <fcntl.h>])

‎src/include/pg_config.h.in

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@
126126
to 0 if you don't. */
127127
#undef HAVE_DECL_LLVMORCGETSYMBOLADDRESSIN
128128

129+
/* Define to 1 if you have the declaration of `memset_s', and to 0 if you
130+
don't. */
131+
#undef HAVE_DECL_MEMSET_S
132+
129133
/* Define to 1 if you have the declaration of `posix_fadvise', and to 0 if you
130134
don't. */
131135
#undef HAVE_DECL_POSIX_FADVISE
@@ -383,9 +387,6 @@
383387
/* Define to 1 if you have the <memory.h> header file. */
384388
#undef HAVE_MEMORY_H
385389

386-
/* Define to 1 if you have the `memset_s' function. */
387-
#undef HAVE_MEMSET_S
388-
389390
/* Define to 1 if the system has the type `MINIDUMP_TYPE'. */
390391
#undef HAVE_MINIDUMP_TYPE
391392

‎src/port/explicit_bzero.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@
1212
*-------------------------------------------------------------------------
1313
*/
1414

15+
#define__STDC_WANT_LIB_EXT1__ 1/* needed to access memset_s() */
16+
1517
#include"c.h"
1618

17-
#ifdefined(HAVE_MEMSET_S)
19+
#ifHAVE_DECL_MEMSET_S
1820

1921
void
2022
explicit_bzero(void*buf,size_tlen)

‎src/tools/msvc/Solution.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ sub GenerateFiles
240240
HAVE_DECL_LLVMGETHOSTCPUNAME=> 0,
241241
HAVE_DECL_LLVMGETHOSTCPUFEATURES=> 0,
242242
HAVE_DECL_LLVMORCGETSYMBOLADDRESSIN=> 0,
243+
HAVE_DECL_MEMSET_S=> 0,
243244
HAVE_DECL_POSIX_FADVISE=> 0,
244245
HAVE_DECL_PREADV=> 0,
245246
HAVE_DECL_PWRITEV=> 0,
@@ -321,7 +322,6 @@ sub GenerateFiles
321322
HAVE_MBARRIER_H=>undef,
322323
HAVE_MBSTOWCS_L=> 1,
323324
HAVE_MEMORY_H=> 1,
324-
HAVE_MEMSET_S=>undef,
325325
HAVE_MINIDUMP_TYPE=> 1,
326326
HAVE_MKDTEMP=>undef,
327327
HAVE_NETINET_TCP_H=>undef,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp