Skip to content

Commit 413187f

Browse files
GustavoARSilvakees
authored andcommitted
stddef: Remove token-pasting in TRAILING_OVERLAP()
Currently, TRAILING_OVERLAP() token-pastes the FAM parameter into the name of internal pdding member `__offset_to_##FAM`. This forces FAM to be a single identifier, which prevents callers from using a FAM when it's a nested member. For instance, see the following scenario: | struct flex { | size_t count; | int data[]; | }; | struct foo { | int hdr_foo; | struct flex f; | }; | struct composite { | struct foo hdr; | int data[100]; | }; In this case, it'd be useful if TRAILING_OVERLAP() could be used in the following way: | struct composite { | TRAILING_OVERLAP(struct foo, hdr, f.data, | int data[100]; | ); | }; However, this is not current possible due to the token concatenation in `__offset_to_##FAM`, which fails when FAM contains a dot. So, remove token-pasting and use the fixed internal name `__offset_to_FAM` and, with this, expand the capabilities of TRAILING_OVERLAP(). :) Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org> Link: https://lore.kernel.org/r/13b3e0a69aad837b4e32ca8269b9d91bf1fbe9ef.1758115257.git.gustavoars@kernel.org Signed-off-by: Kees Cook <kees@kernel.org>
1 parent 01c7344 commit 413187f

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

include/linux/stddef.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ enum {
108108
union { \
109109
TYPE NAME; \
110110
struct { \
111-
unsigned char __offset_to_##FAM[offsetof(TYPE, FAM)]; \
111+
unsigned char __offset_to_FAM[offsetof(TYPE, FAM)]; \
112112
MEMBERS \
113113
}; \
114114
}

0 commit comments

Comments
 (0)