KEYS: Avoid -Wflex-array-member-not-at-end warning
Subsystems (3)
PATCH 1/1 KEYS: Avoid -Wflex-array-member-not-at-end warning
-Wflex-array-member-not-at-end was introduced in GCC-14, and we are getting ready to enable it, globally.
Use the new TRAILING_OVERLAP() helper to fix the following warning:
crypto/asymmetric_keys/restrict.c:20:34: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
This helper creates a union between a flexible-array member (FAM) and a set of MEMBERS that would otherwise follow it.
This overlays the trailing MEMBER unsigned char data[10]; onto the FAM struct asymmetric_key_id::data[], while keeping the FAM and the start of MEMBER aligned.
The static_assert() ensures this alignment remains, and it's intentionally placed inmediately after the corresponding structures --no blank line in between.
--- crypto/asymmetric_keys/restrict.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
crypto/asymmetric_keys/restrict.c +5 -2
@@ -17,9 +17,12 @@ static struct asymmetric_key_id *ca_keyid;#ifndef MODULE static struct { -struct asymmetric_key_id id; -unsigned char data[10 ]; +/* Must be last as it ends in a flexible-array member. */ + TRAILING_OVERLAP(struct asymmetric_key_id, id, data, + unsigned char data[10]; + ); } cakey; +static_assert(offsetof(typeof(cakey), id.data) == offsetof(typeof(cakey), data));static int __init ca_keys_setup (char *str) {
Signature · 1 line
2.43.0
Quoted 15 lines · Gustavo A. R. Silva
-Wflex-array-member-not-at-end was introduced in GCC-14, and we are getting ready to enable it, globally.
Use the new
TRAILING_OVERLAP()helper to fix the following warning:
crypto/asymmetric_keys/restrict.c:20:34: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]This helper creates a union between a flexible-array member (FAM) and a set of MEMBERS that would otherwise follow it.
This overlays the trailing MEMBER unsigned char data[10]; onto the FAM struct asymmetric_key_id::data[], while keeping the FAM and the start of MEMBER aligned.
Quoted 5 lines
The
static_assert()ensures this alignment remains, and it's intentionally placed inmediately after the corresponding structures --no blank line in between.Signed-off-by Gustavo A. R. Silva <[email protected]>
Quoted 10 lines
--- crypto/asymmetric_keys/restrict.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)crypto/asymmetric_keys/restrict.c +0
-0@@ -17,9 +17,12 @@ static struct asymmetric_key_id *ca_keyid;
crypto/asymmetric_keys/restrict.c static struct asymmetric_key_id *ca_keyid; · line 25
Quoted 10 lines
crypto/asymmetric_keys/restrict.c +5
-2#ifndef MODULE static struct { -struct asymmetric_key_id id; -unsigned char data[10 ]; +/* Must be last as it ends in a flexible-array member. */ + TRAILING_OVERLAP(struct asymmetric_key_id, id, data, + unsigned char data[10]; + ); } cakey; +static_assert(offsetof(typeof(cakey), id.data) == offsetof(typeof(cakey), data));
The whole thing looks a bit convoluted to me just to declare a fixed-sized static buffer and call sizeof() in one place in the code. But I couldn't come up with a better refactor not introducing potential alignment side-effects. So LGTM.
Quoted 5 lines
crypto/asymmetric_keys/restrict.c +0
-1static int __init ca_keys_setup (char *str) { --2.43.0
Herbert Xu
maintainerQuoted 14 lines · Gustavo A. R. Silva
-Wflex-array-member-not-at-end was introduced in GCC-14, and we are getting ready to enable it, globally.
Use the new
TRAILING_OVERLAP()helper to fix the following warning:
crypto/asymmetric_keys/restrict.c:20:34: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]This helper creates a union between a flexible-array member (FAM) and a set of MEMBERS that would otherwise follow it.
This overlays the trailing MEMBER unsigned char data[10]; onto the FAM struct asymmetric_key_id::data[], while keeping the FAM and the start of MEMBER aligned.
Quoted 8 lines
The
static_assert()ensures this alignment remains, and it's intentionally placed inmediately after the corresponding structures --no blank line in between.Signed-off-by Gustavo A. R. Silva <[email protected]>--- crypto/asymmetric_keys/restrict.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
Patch applied. Thanks.
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt