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

Commit9bc2d37

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 parent24d3903 commit9bc2d37

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
@@ -15789,7 +15789,7 @@ fi
1578915789
LIBS_including_readline="$LIBS"
1579015790
LIBS=`echo "$LIBS" | sed -e 's/-ledit//g' -e 's/-lreadline//g'`
1579115791

15792-
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 setproctitle setproctitle_fast setsid shm_open strsignal symlink sync_file_range uselocale wcstombs_l
15792+
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 setproctitle setproctitle_fast setsid shm_open strsignal symlink sync_file_range uselocale wcstombs_l
1579315793
do :
1579415794
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
1579515795
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
@@ -16321,6 +16321,19 @@ cat >>confdefs.h <<_ACEOF
1632116321
#define HAVE_DECL_STRCHRNUL $ac_have_decl
1632216322
_ACEOF
1632316323

16324+
ac_fn_c_check_decl "$LINENO" "memset_s" "ac_cv_have_decl_memset_s" "#define __STDC_WANT_LIB_EXT1__ 1
16325+
#include <string.h>
16326+
"
16327+
if test "x$ac_cv_have_decl_memset_s" = xyes; then :
16328+
ac_have_decl=1
16329+
else
16330+
ac_have_decl=0
16331+
fi
16332+
16333+
cat >>confdefs.h <<_ACEOF
16334+
#define HAVE_DECL_MEMSET_S $ac_have_decl
16335+
_ACEOF
16336+
1632416337

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

‎configure.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1750,7 +1750,6 @@ AC_CHECK_FUNCS(m4_normalize([
17501750
getrlimit
17511751
kqueue
17521752
mbstowcs_l
1753-
memset_s
17541753
poll
17551754
posix_fallocate
17561755
ppoll
@@ -1799,6 +1798,8 @@ AC_CHECK_DECLS([strlcat, strlcpy, strnlen])
17991798
# We can't use AC_REPLACE_FUNCS to replace these functions, because it
18001799
# won't handle deployment target restrictions on macOS
18011800
AC_CHECK_DECLS([strchrnul], [], [], [#include <string.h>])
1801+
AC_CHECK_DECLS([memset_s], [], [], [#define __STDC_WANT_LIB_EXT1__ 1
1802+
#include <string.h>])
18021803

18031804
# This is probably only present on macOS, but may as well check always
18041805
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
@@ -365,9 +369,6 @@
365369
/* Define to 1 if you have the <memory.h> header file. */
366370
#undef HAVE_MEMORY_H
367371

368-
/* Define to 1 if you have the `memset_s' function. */
369-
#undef HAVE_MEMSET_S
370-
371372
/* Define to 1 if the system has the type `MINIDUMP_TYPE'. */
372373
#undef HAVE_MINIDUMP_TYPE
373374

‎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_RTLD_GLOBAL=> 0,
245246
HAVE_DECL_RTLD_NOW=> 0,
@@ -313,7 +314,6 @@ sub GenerateFiles
313314
HAVE_MBARRIER_H=>undef,
314315
HAVE_MBSTOWCS_L=> 1,
315316
HAVE_MEMORY_H=> 1,
316-
HAVE_MEMSET_S=>undef,
317317
HAVE_MINIDUMP_TYPE=> 1,
318318
HAVE_MKDTEMP=>undef,
319319
HAVE_NETINET_TCP_H=>undef,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp