linux-api.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] uapi: partially fix __DECLARE_FLEX_ARRAY for C++
@ 2023-09-08 11:32 Alexey Dobriyan
  2023-09-08 15:14 ` [PATCH v2] uapi: " Alexey Dobriyan
  0 siblings, 1 reply; 10+ messages in thread
From: Alexey Dobriyan @ 2023-09-08 11:32 UTC (permalink / raw)
  To: akpm; +Cc: linux-kernel, linux-api, keescook

__DECLARE_FLEX_ARRAY(T, member) macro expands to

	struct {
		struct {} __empty_member;
		T member[];
	};

which is subtly wrong in C++ because sizeof(struct{}) is 1 not 0,
changing UAPI structures layouts.

This can be fixed by expanding simply to

	T member[];

Most of the usages still be broken because of other C++ shenanigans
but this fixes simplest usage: 1 flexible member at the end.

Fix header guard while I'm at it.

Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
---

 include/uapi/linux/stddef.h |    6 ++++++
 1 file changed, 6 insertions(+)

--- a/include/uapi/linux/stddef.h
+++ b/include/uapi/linux/stddef.h
@@ -39,6 +39,10 @@
  * struct, it needs to be wrapped in an anonymous struct with at least 1
  * named member, but that member can be empty.
  */
+#ifdef __cplusplus
+#define __DECLARE_FLEX_ARRAY(T, member)		\
+	T member[]
+#else
 #define __DECLARE_FLEX_ARRAY(TYPE, NAME)	\
 	struct { \
 		struct { } __empty_ ## NAME; \
@@ -49,3 +53,5 @@
 #ifndef __counted_by
 #define __counted_by(m)
 #endif
+
+#endif

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2023-09-15 19:15 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-08 11:32 [PATCH] uapi: partially fix __DECLARE_FLEX_ARRAY for C++ Alexey Dobriyan
2023-09-08 15:14 ` [PATCH v2] uapi: " Alexey Dobriyan
2023-09-08 15:53   ` Kees Cook
2023-09-08 16:03     ` Alexey Dobriyan
2023-09-08 16:11       ` Kees Cook
2023-09-11  8:19         ` David Laight
2023-09-12 15:06           ` Alexey Dobriyan
2023-09-12 16:22           ` [PATCH v3 1/2] " Alexey Dobriyan
2023-09-12 16:23             ` [PATCH v3 2/2] uapi: fix header guard in include/uapi/linux/stddef.h Alexey Dobriyan
2023-09-15 19:14             ` [PATCH v3 1/2] uapi: fix __DECLARE_FLEX_ARRAY for C++ Kees Cook

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).