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

Commita1e0e70

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 parent9a8df96 commita1e0e70

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
@@ -16037,7 +16037,7 @@ fi
1603716037
LIBS_including_readline="$LIBS"
1603816038
LIBS=`echo "$LIBS" | sed -e 's/-ledit//g' -e 's/-lreadline//g'`
1603916039

16040-
for ac_func in backtrace_symbols clock_gettime copyfile fdatasync getifaddrs getpeerucred getrlimit 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
16040+
for ac_func in backtrace_symbols clock_gettime copyfile fdatasync getifaddrs getpeerucred getrlimit 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
1604116041
do :
1604216042
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
1604316043
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
@@ -16613,6 +16613,19 @@ cat >>confdefs.h <<_ACEOF
1661316613
#define HAVE_DECL_STRCHRNUL $ac_have_decl
1661416614
_ACEOF
1661516615

16616+
ac_fn_c_check_decl "$LINENO" "memset_s" "ac_cv_have_decl_memset_s" "#define __STDC_WANT_LIB_EXT1__ 1
16617+
#include <string.h>
16618+
"
16619+
if test "x$ac_cv_have_decl_memset_s" = xyes; then :
16620+
ac_have_decl=1
16621+
else
16622+
ac_have_decl=0
16623+
fi
16624+
16625+
cat >>confdefs.h <<_ACEOF
16626+
#define HAVE_DECL_MEMSET_S $ac_have_decl
16627+
_ACEOF
16628+
1661616629

1661716630
# This is probably only present on macOS, but may as well check always
1661816631
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
@@ -1795,7 +1795,6 @@ AC_CHECK_FUNCS(m4_normalize([
17951795
getrlimit
17961796
kqueue
17971797
mbstowcs_l
1798-
memset_s
17991798
poll
18001799
posix_fallocate
18011800
ppoll
@@ -1849,6 +1848,8 @@ AC_CHECK_DECLS([strlcat, strlcpy, strnlen])
18491848
AC_CHECK_DECLS([preadv],[],[AC_LIBOBJ(preadv)],[#include <sys/uio.h>])
18501849
AC_CHECK_DECLS([pwritev],[],[AC_LIBOBJ(pwritev)],[#include <sys/uio.h>])
18511850
AC_CHECK_DECLS([strchrnul],[],[],[#include <string.h>])
1851+
AC_CHECK_DECLS([memset_s],[],[],[#define __STDC_WANT_LIB_EXT1__ 1
1852+
#include <string.h>])
18521853

18531854
# This is probably only present on macOS, but may as well check always
18541855
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
@@ -135,6 +135,10 @@
135135
to 0 if you don't. */
136136
#undef HAVE_DECL_LLVMORCGETSYMBOLADDRESSIN
137137

138+
/* Define to 1 if you have the declaration of `memset_s', and to 0 if you
139+
don't. */
140+
#undef HAVE_DECL_MEMSET_S
141+
138142
/* Define to 1 if you have the declaration of `posix_fadvise', and to 0 if you
139143
don't. */
140144
#undef HAVE_DECL_POSIX_FADVISE
@@ -385,9 +389,6 @@
385389
/* Define to 1 if you have the <memory.h> header file. */
386390
#undef HAVE_MEMORY_H
387391

388-
/* Define to 1 if you have the `memset_s' function. */
389-
#undef HAVE_MEMSET_S
390-
391392
/* Define to 1 if the system has the type `MINIDUMP_TYPE'. */
392393
#undef HAVE_MINIDUMP_TYPE
393394

‎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
@@ -243,6 +243,7 @@ sub GenerateFiles
243243
HAVE_DECL_LLVMGETHOSTCPUNAME=> 0,
244244
HAVE_DECL_LLVMGETHOSTCPUFEATURES=> 0,
245245
HAVE_DECL_LLVMORCGETSYMBOLADDRESSIN=> 0,
246+
HAVE_DECL_MEMSET_S=> 0,
246247
HAVE_DECL_POSIX_FADVISE=> 0,
247248
HAVE_DECL_PREADV=> 0,
248249
HAVE_DECL_PWRITEV=> 0,
@@ -322,7 +323,6 @@ sub GenerateFiles
322323
HAVE_MBARRIER_H=>undef,
323324
HAVE_MBSTOWCS_L=> 1,
324325
HAVE_MEMORY_H=> 1,
325-
HAVE_MEMSET_S=>undef,
326326
HAVE_MINIDUMP_TYPE=> 1,
327327
HAVE_MKDTEMP=>undef,
328328
HAVE_NETINET_TCP_H=>undef,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp