git: 5af6fbd72790 - main - ssp: appease -Wgnu-statement-expression-from-macro-expansion

From: Kyle Evans <kevans_at_FreeBSD.org>
Date: Tue, 14 May 2024 23:22:42 UTC
The branch main has been updated by kevans:

URL: https://cgit.FreeBSD.org/src/commit/?id=5af6fbd72790173e128222943effc5aa95272ce9

commit 5af6fbd72790173e128222943effc5aa95272ce9
Author:     Kyle Evans <kevans@FreeBSD.org>
AuthorDate: 2024-05-14 23:16:58 +0000
Commit:     Kyle Evans <kevans@FreeBSD.org>
CommitDate: 2024-05-14 23:22:18 +0000

    ssp: appease -Wgnu-statement-expression-from-macro-expansion
    
    It's a stupid warning, but some ports enable it by default and were
    already defining _FORTIFY_SOURCE, thus exposing the new macros
    immediately.  This at least fixes the libfido2 build, perhaps others as
    well.
    
    While we're here, fix a fresh build of stand w/ FORTIFY_SOURCE enabled
    by not pulling in the ssp headers if _STANDALONE is defined.  We do not
    have runtime support in libsa as of the time of writing.
    
    Reported by:    netchild
    Sponsored by:   Stormshield
    Sponsored by:   Klara, Inc.
---
 include/ssp/stdio.h   | 10 +++++-----
 include/ssp/string.h  |  4 ++--
 include/ssp/strings.h |  4 ++--
 include/stdio.h       |  2 +-
 include/string.h      |  2 +-
 include/strings.h     |  2 +-
 include/unistd.h      |  2 +-
 7 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/include/ssp/stdio.h b/include/ssp/stdio.h
index ed7303497a45..4bca1de7d4f9 100644
--- a/include/ssp/stdio.h
+++ b/include/ssp/stdio.h
@@ -53,31 +53,31 @@ __END_DECLS
 
 #if __SSP_FORTIFY_LEVEL > 0
 
-#define sprintf(str, ...) ({	\
+#define sprintf(str, ...) __extension__ ({	\
     char *_ssp_str = (str);	\
     __builtin___sprintf_chk(_ssp_str, 0, __ssp_bos(_ssp_str),		\
         __VA_ARGS__); \
 })
 
-#define vsprintf(str, fmt, ap) ({	\
+#define vsprintf(str, fmt, ap) __extension__ ({	\
     char *_ssp_str = (str);		\
     __builtin___vsprintf_chk(_ssp_str, 0, __ssp_bos(_ssp_str), fmt,	\
         ap);				\
 })
 
-#define snprintf(str, len, ...) ({	\
+#define snprintf(str, len, ...) __extension__ ({	\
     char *_ssp_str = (str);		\
     __builtin___snprintf_chk(_ssp_str, len, 0, __ssp_bos(_ssp_str),	\
         __VA_ARGS__);			\
 })
 
-#define vsnprintf(str, len, fmt, ap) ({	\
+#define vsnprintf(str, len, fmt, ap) __extension__ ({	\
     char *_ssp_str = (str);		\
     __builtin___vsnprintf_chk(_ssp_str, len, 0, __ssp_bos(_ssp_str),	\
         fmt, ap);			\
 })
 
-#define fgets(str, len, fp) ({		\
+#define fgets(str, len, fp) __extension__ ({		\
     char *_ssp_str = (str);		\
     __fgets_chk(_ssp_str, len, __ssp_bos(_ssp_str), fp);	\
 })
diff --git a/include/ssp/string.h b/include/ssp/string.h
index 996020fda778..ceb4ba2a2174 100644
--- a/include/ssp/string.h
+++ b/include/ssp/string.h
@@ -51,7 +51,7 @@ __END_DECLS
 #if __SSP_FORTIFY_LEVEL > 0
 
 #define __ssp_bos_check3_typed_var(fun, dsttype, dsrvar, dst, srctype, srcvar, \
-    src, lenvar, len) ({				\
+    src, lenvar, len) __extension__ ({				\
     srctype srcvar = (src);				\
     dsttype dstvar = (dst);				\
     size_t lenvar = (len);				\
@@ -69,7 +69,7 @@ __END_DECLS
     __ssp_bos_check3_typed_var(fun, void *, __ssp_var(dstv), dst,	\
         const void *, __ssp_var(srcv), src, __ssp_var(lenv), len)
 
-#define __ssp_bos_check2_var(fun, dstvar, dst, srcvar, src) ({		\
+#define __ssp_bos_check2_var(fun, dstvar, dst, srcvar, src) __extension__ ({ 	\
     const void *srcvar = (src);				\
     void *dstvar = (dst);				\
     ((__ssp_bos0(dstvar) != (size_t)-1) ?		\
diff --git a/include/ssp/strings.h b/include/ssp/strings.h
index 06c9c7cc0a09..51b11a14ee87 100644
--- a/include/ssp/strings.h
+++ b/include/ssp/strings.h
@@ -39,7 +39,7 @@
 
 #if __SSP_FORTIFY_LEVEL > 0
 
-#define _ssp_bcopy(srcvar, src, dstvar, dst, lenvar,  len) ({	\
+#define _ssp_bcopy(srcvar, src, dstvar, dst, lenvar,  len) __extension__ ({ \
     const void *srcvar = (src);			\
     void *dstvar = (dst);			\
     size_t lenvar = (len);			\
@@ -52,7 +52,7 @@
 #define	bcopy(src, dst, len)			\
     _ssp_bcopy(__ssp_var(srcv), src, __ssp_var(dstv), dst, __ssp_var(lenv), len)
 
-#define _ssp_bzero(dstvar, dst, lenvar, len) ({		\
+#define _ssp_bzero(dstvar, dst, lenvar, len) __extension__ ({		\
     void *dstvar = (dst);			\
     size_t lenvar = (len);			\
     ((__ssp_bos0(dstvar) != (size_t)-1) ?	\
diff --git a/include/stdio.h b/include/stdio.h
index 30bc638082d8..ea53816cf1d4 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -530,7 +530,7 @@ extern int __isthreaded;
 __END_DECLS
 __NULLABILITY_PRAGMA_POP
 
-#if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0
+#if !defined(_STANDALONE) && defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0
 #include <ssp/stdio.h>
 #endif
 #endif /* !_STDIO_H_ */
diff --git a/include/string.h b/include/string.h
index a595f6e3e260..ce605117daa6 100644
--- a/include/string.h
+++ b/include/string.h
@@ -168,7 +168,7 @@ errno_t memset_s(void *, rsize_t, int, rsize_t);
 #endif /* __EXT1_VISIBLE */
 __END_DECLS
 
-#if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0
+#if !defined(_STANDALONE) && defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0
 #include <ssp/string.h>
 #endif
 #endif /* _STRING_H_ */
diff --git a/include/strings.h b/include/strings.h
index 6fe6a09e7dd3..511f7c03cb3c 100644
--- a/include/strings.h
+++ b/include/strings.h
@@ -68,7 +68,7 @@ int	 strncasecmp(const char *, const char *, size_t) __pure;
 #endif
 __END_DECLS
 
-#if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0
+#if !defined(_STANDALONE) && defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0
 #include <ssp/strings.h>
 #endif
 #endif /* _STRINGS_H_ */
diff --git a/include/unistd.h b/include/unistd.h
index 59738cbf6e68..48155bb2971b 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -37,7 +37,7 @@
 #include <sys/_null.h>
 #include <sys/_types.h>
 
-#if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0
+#if !defined(_STANDALONE) && defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0
 #include <ssp/unistd.h>
 #endif