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

Commit253cf66

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 parentcc112eb commit253cf66

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
@@ -15715,7 +15715,7 @@ fi
1571515715
LIBS_including_readline="$LIBS"
1571615716
LIBS=`echo "$LIBS" | sed -e 's/-ledit//g' -e 's/-lreadline//g'`
1571715717

15718-
for ac_func in backtrace_symbols copyfile 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
15718+
for ac_func in backtrace_symbols copyfile 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
1571915719
do :
1572015720
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
1572115721
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
@@ -16291,6 +16291,19 @@ cat >>confdefs.h <<_ACEOF
1629116291
#define HAVE_DECL_STRCHRNUL $ac_have_decl
1629216292
_ACEOF
1629316293

16294+
ac_fn_c_check_decl "$LINENO" "memset_s" "ac_cv_have_decl_memset_s" "#define __STDC_WANT_LIB_EXT1__ 1
16295+
#include <string.h>
16296+
"
16297+
if test "x$ac_cv_have_decl_memset_s" = xyes; then :
16298+
ac_have_decl=1
16299+
else
16300+
ac_have_decl=0
16301+
fi
16302+
16303+
cat >>confdefs.h <<_ACEOF
16304+
#define HAVE_DECL_MEMSET_S $ac_have_decl
16305+
_ACEOF
16306+
1629416307

1629516308
# This is probably only present on macOS, but may as well check always
1629616309
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
@@ -1803,7 +1803,6 @@ AC_CHECK_FUNCS(m4_normalize([
18031803
inet_pton
18041804
kqueue
18051805
mbstowcs_l
1806-
memset_s
18071806
posix_fallocate
18081807
ppoll
18091808
pthread_is_threaded_np
@@ -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>])

‎meson.build

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2324,26 +2324,29 @@ decl_checks += [
23242324
['preadv','sys/uio.h'],
23252325
['pwritev','sys/uio.h'],
23262326
['strchrnul','string.h'],
2327+
['memset_s','string.h','#define __STDC_WANT_LIB_EXT1__ 1'],
23272328
]
23282329

23292330
foreachc: decl_checks
23302331
func= c.get(0)
23312332
header= c.get(1)
2332-
args= c.get(2, {})
2333+
prologue= c.get(2,'')
2334+
args= c.get(3, {})
23332335
varname='HAVE_DECL_'+ func.underscorify().to_upper()
23342336

23352337
found= cc.compiles('''
2336-
#include <@0@>
2338+
@0@
2339+
#include <@1@>
23372340
23382341
int main()
23392342
{
2340-
#ifndef @1@
2341-
(void) @1@;
2343+
#ifndef @2@
2344+
(void) @2@;
23422345
#endif
23432346
23442347
return 0;
23452348
}
2346-
'''.format(header, func),
2349+
'''.format(prologue,header, func),
23472350
name:'test whether @0@ is declared'.format(func),
23482351
# need to add cflags_warn to get at least
23492352
# -Werror=unguarded-availability-new if applicable
@@ -2581,7 +2584,6 @@ func_checks = [
25812584
['inet_pton'],
25822585
['kqueue'],
25832586
['mbstowcs_l'],
2584-
['memset_s'],
25852587
['mkdtemp'],
25862588
['posix_fadvise'],
25872589
['posix_fallocate'],

‎src/include/pg_config.h.in

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

119+
/* Define to 1 if you have the declaration of `memset_s', and to 0 if you
120+
don't. */
121+
#undef HAVE_DECL_MEMSET_S
122+
119123
/* Define to 1 if you have the declaration of `posix_fadvise', and to 0 if you
120124
don't. */
121125
#undef HAVE_DECL_POSIX_FADVISE
@@ -317,9 +321,6 @@
317321
/* Define to 1 if you have the <memory.h> header file. */
318322
#undef HAVE_MEMORY_H
319323

320-
/* Define to 1 if you have the `memset_s' function. */
321-
#undef HAVE_MEMSET_S
322-
323324
/* Define to 1 if you have the `mkdtemp' function. */
324325
#undef HAVE_MKDTEMP
325326

‎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