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

Commit5355a24

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 parent83dbe8a commit5355a24

File tree

5 files changed

+31
-12
lines changed

5 files changed

+31
-12
lines changed

‎configure

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

15275-
for ac_func in backtrace_symbols copyfile copy_file_range getifaddrs getpeerucred inet_pton kqueue mbstowcs_lmemset_sposix_fallocate ppoll pthread_is_threaded_np setproctitle setproctitle_fast strsignal syncfs sync_file_range uselocale wcstombs_l
15275+
for ac_func in backtrace_symbols copyfile copy_file_range getifaddrs getpeerucred inet_pton kqueue mbstowcs_l posix_fallocate ppoll pthread_is_threaded_np setproctitle setproctitle_fast strsignal syncfs sync_file_range uselocale wcstombs_l
1527615276
do :
1527715277
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
1527815278
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
@@ -15828,6 +15828,19 @@ cat >>confdefs.h <<_ACEOF
1582815828
#define HAVE_DECL_STRCHRNUL $ac_have_decl
1582915829
_ACEOF
1583015830

15831+
ac_fn_c_check_decl "$LINENO" "memset_s" "ac_cv_have_decl_memset_s" "#define __STDC_WANT_LIB_EXT1__ 1
15832+
#include <string.h>
15833+
"
15834+
if test "x$ac_cv_have_decl_memset_s" = xyes; then :
15835+
ac_have_decl=1
15836+
else
15837+
ac_have_decl=0
15838+
fi
15839+
15840+
cat >>confdefs.h <<_ACEOF
15841+
#define HAVE_DECL_MEMSET_S $ac_have_decl
15842+
_ACEOF
15843+
1583115844

1583215845
# This is probably only present on macOS, but may as well check always
1583315846
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
@@ -1757,7 +1757,6 @@ AC_CHECK_FUNCS(m4_normalize([
17571757
inet_pton
17581758
kqueue
17591759
mbstowcs_l
1760-
memset_s
17611760
posix_fallocate
17621761
ppoll
17631762
pthread_is_threaded_np
@@ -1803,6 +1802,8 @@ AC_CHECK_DECLS([strlcat, strlcpy, strnlen])
18031802
AC_CHECK_DECLS([preadv],[],[],[#include <sys/uio.h>])
18041803
AC_CHECK_DECLS([pwritev],[],[],[#include <sys/uio.h>])
18051804
AC_CHECK_DECLS([strchrnul],[],[],[#include <string.h>])
1805+
AC_CHECK_DECLS([memset_s],[],[],[#define __STDC_WANT_LIB_EXT1__ 1
1806+
#include <string.h>])
18061807

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

‎meson.build

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2470,6 +2470,7 @@ decl_checks += [
24702470
['preadv','sys/uio.h'],
24712471
['pwritev','sys/uio.h'],
24722472
['strchrnul','string.h'],
2473+
['memset_s','string.h','#define __STDC_WANT_LIB_EXT1__ 1'],
24732474
]
24742475

24752476
# Check presence of some optional LLVM functions.
@@ -2483,21 +2484,23 @@ endif
24832484
foreachc: decl_checks
24842485
func= c.get(0)
24852486
header= c.get(1)
2486-
args= c.get(2, {})
2487+
prologue= c.get(2,'')
2488+
args= c.get(3, {})
24872489
varname='HAVE_DECL_'+ func.underscorify().to_upper()
24882490

24892491
found= cc.compiles('''
2490-
#include <@0@>
2492+
@0@
2493+
#include <@1@>
24912494
24922495
int main()
24932496
{
2494-
#ifndef @1@
2495-
(void) @1@;
2497+
#ifndef @2@
2498+
(void) @2@;
24962499
#endif
24972500
24982501
return 0;
24992502
}
2500-
'''.format(header, func),
2503+
'''.format(prologue,header, func),
25012504
name:'test whether @0@ is declared'.format(func),
25022505
# need to add cflags_warn to get at least
25032506
# -Werror=unguarded-availability-new if applicable
@@ -2726,7 +2729,6 @@ func_checks = [
27262729
['inet_pton'],
27272730
['kqueue'],
27282731
['mbstowcs_l'],
2729-
['memset_s'],
27302732
['mkdtemp'],
27312733
['posix_fadvise'],
27322734
['posix_fallocate'],

‎src/include/pg_config.h.in

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@
103103
`LLVMCreatePerfJITEventListener', and to 0 if you don't. */
104104
#undef HAVE_DECL_LLVMCREATEPERFJITEVENTLISTENER
105105

106+
/* Define to 1 if you have the declaration of `memset_s', and to 0 if you
107+
don't. */
108+
#undef HAVE_DECL_MEMSET_S
109+
106110
/* Define to 1 if you have the declaration of `posix_fadvise', and to 0 if you
107111
don't. */
108112
#undef HAVE_DECL_POSIX_FADVISE
@@ -301,9 +305,6 @@
301305
/* Define to 1 if you have the <memory.h> header file. */
302306
#undef HAVE_MEMORY_H
303307

304-
/* Define to 1 if you have the `memset_s' function. */
305-
#undef HAVE_MEMSET_S
306-
307308
/* Define to 1 if you have the `mkdtemp' function. */
308309
#undef HAVE_MKDTEMP
309310

‎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)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp