smb: smb2pdu.h: Use static_assert() to check struct sizes
Subsystems (2)
PATCH 1/1 smb: smb2pdu.h: Use static_assert() to check struct sizes
Commit 9f9bef9bc5c6 ("smb: smb2pdu.h: Avoid -Wflex-array-member-not-at-end warnings") introduced tagged struct create_context_hdr. We want to ensure that when new members need to be added to the flexible structure, they are always included within this tagged struct.
So, we use static_assert() to ensure that the memory layout for both the flexible structure and the tagged struct is the same after any changes.
--- fs/smb/common/smb2pdu.h | 2 ++ 1 file changed, 2 insertions(+)
fs/smb/common/smb2pdu.h +2 -0
@@ -1216,6 +1216,8 @@ struct create_context { );__u8 Buffer[]; } __packed; +static_assert (offsetof(struct create_context , Buffer) ==sizeof (struct create_context_hdr ), +"struct member likely outside of __struct_group()" );struct smb2_create_req {struct smb2_hdr hdr;
Signature · 1 line
2.34.1
2024년 8월 9일 (금) 오전 7:04, Gustavo A. R. Silva <[email protected]>님이 작성:
Quoted 11 lines
Commit
9f9bef9bc5c6("smb:smb2pdu.h: Avoid -Wflex-array-member-not-at-end warnings") introduced taggedstruct create_context_hdr. We want to ensure that when new members need to be added to the flexible structure, they are always included within this tagged struct.So, we use
static_assert()to ensure that the memory layout for both the flexible structure and the tagged struct is the same after any changes.Signed-off-by Gustavo A. R. Silva <[email protected]>
Thanks!
Steve French
Appliedmerged into cifs-2.6.git for-next
Quoted 17 lines · Namjae Jeon
2024년 8월 9일 (금) 오전 7:04, Gustavo A. R. Silva <[email protected]>님이 작성:
Quoted 11 lines
Commit
9f9bef9bc5c6("smb:smb2pdu.h: Avoid -Wflex-array-member-not-at-end warnings") introduced taggedstruct create_context_hdr. We want to ensure that when new members need to be added to the flexible structure, they are always included within this tagged struct.So, we use
static_assert()to ensure that the memory layout for both the flexible structure and the tagged struct is the same after any changes.Signed-off-by Gustavo A. R. Silva <[email protected]>Acked-by Namjae Jeon <[email protected]>Thanks!
Signature · 3 lines
Thanks, Steve