summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2025-05-18 12:45:55 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2025-05-18 12:45:55 -0400
commit5355a2400e847b1a7e7a3d9eea9516588d0fad91 (patch)
tree4bb3c1092abb718cc5181eeff256f6f43d430ca7 /src
parent83dbe8aacdbdb3d297b113d0ccb5c0ab1e699802 (diff)
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 to have access to memset_s(). It appears that many platforms are lenient about this, because we weren't doing it and yet the code appeared to work anyway. But we now find that with -std=c11, macOS is strict and doesn't declare memset_s, leading to compile failures since we try to use it anyway. (Given the lack of prior reports, perhaps this is new behavior in the latest SDK? No matter, we're clearly in the wrong.) In addition to the immediate problem, which could be fixed merely by adding the needed #define to explicit_bzero.c, it seems possible that our configure-time probe for memset_s() could fail in case a platform implements the function in some odd way due to this spec requirement. This concern can be fixed in largely the same way that we dealt with strchrnul() in 6da2ba1d8: switch to using a declaration-based configure 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.com Backpatch-through: 13
Diffstat (limited to 'src')
-rw-r--r--src/include/pg_config.h.in7
-rw-r--r--src/port/explicit_bzero.c4
2 files changed, 7 insertions, 4 deletions
diff --git a/src/include/pg_config.h.in b/src/include/pg_config.h.in
index 0ee4a63eaa6..1371ac055f4 100644
--- a/src/include/pg_config.h.in
+++ b/src/include/pg_config.h.in
@@ -103,6 +103,10 @@
`LLVMCreatePerfJITEventListener', and to 0 if you don't. */
#undef HAVE_DECL_LLVMCREATEPERFJITEVENTLISTENER
+/* Define to 1 if you have the declaration of `memset_s', and to 0 if you
+ don't. */
+#undef HAVE_DECL_MEMSET_S
+
/* Define to 1 if you have the declaration of `posix_fadvise', and to 0 if you
don't. */
#undef HAVE_DECL_POSIX_FADVISE
@@ -301,9 +305,6 @@
/* Define to 1 if you have the <memory.h> header file. */
#undef HAVE_MEMORY_H
-/* Define to 1 if you have the `memset_s' function. */
-#undef HAVE_MEMSET_S
-
/* Define to 1 if you have the `mkdtemp' function. */
#undef HAVE_MKDTEMP
diff --git a/src/port/explicit_bzero.c b/src/port/explicit_bzero.c
index 735e21c8b36..7d2ad7439f7 100644
--- a/src/port/explicit_bzero.c
+++ b/src/port/explicit_bzero.c
@@ -12,9 +12,11 @@
*-------------------------------------------------------------------------
*/
+#define __STDC_WANT_LIB_EXT1__ 1 /* needed to access memset_s() */
+
#include "c.h"
-#if defined(HAVE_MEMSET_S)
+#if HAVE_DECL_MEMSET_S
void
explicit_bzero(void *buf, size_t len)