Skip to content

Commit 95f3427

Browse files
GustavoARSilvatorvalds
authored andcommitted
ocfs2: ocfs2_fs.h: replace zero-length array with flexible-array member
The current codebase makes use of the zero-length array language extension to the C90 standard, but the preferred mechanism to declare variable-length types such as these ones is a flexible array member[1][2], introduced in C99: struct foo { int stuff; struct boo array[]; }; By making use of the mechanism above, we will get a compiler warning in case the flexible array does not occur last in the structure, which will help us prevent some kind of undefined behavior bugs from being inadvertently introduced[3] to the codebase from now on. Also, notice that, dynamic memory allocations won't be affected by this change: "Flexible array members have incomplete type, and so the sizeof operator may not be applied. As a quirk of the original implementation of zero-length arrays, sizeof evaluates to zero."[1] This issue was found with the help of Coccinelle. [1] https://urldefense.com/v3/__https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html__;!!GqivPVa7Brio!OKPotRhYhHbCG2kibo8Q6_6CuKaa28d_74h1svxyR6rbshrK2L_BdrQpNbvJWBWb40QCkg$ [2] https://urldefense.com/v3/__https://github.com/KSPP/linux/issues/21__;!!GqivPVa7Brio!OKPotRhYhHbCG2kibo8Q6_6CuKaa28d_74h1svxyR6rbshrK2L_BdrQpNbvJWBUhNn9M6g$ [3] commit 7649773 ("cxgb3/l2t: Fix undefined behaviour") Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Acked-by: Joseph Qi <joseph.qi@linux.alibaba.com> Cc: Mark Fasheh <mark@fasheh.com> Cc: Joel Becker <jlbec@evilplan.org> Cc: Junxiao Bi <junxiao.bi@oracle.com> Cc: Changwei Ge <gechangwei@live.cn> Cc: Gang He <ghe@suse.com> Cc: Jun Piao <piaojun@huawei.com> Link: http://lkml.kernel.org/r/20200309202155.GA8432@embeddedor Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 8cb9243 commit 95f3427

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

fs/ocfs2/ocfs2_fs.h

+9-9
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ struct ocfs2_extent_list {
470470
__le16 l_reserved1;
471471
__le64 l_reserved2; /* Pad to
472472
sizeof(ocfs2_extent_rec) */
473-
/*10*/ struct ocfs2_extent_rec l_recs[0]; /* Extent records */
473+
/*10*/ struct ocfs2_extent_rec l_recs[]; /* Extent records */
474474
};
475475

476476
/*
@@ -484,7 +484,7 @@ struct ocfs2_chain_list {
484484
__le16 cl_count; /* Total chains in this list */
485485
__le16 cl_next_free_rec; /* Next unused chain slot */
486486
__le64 cl_reserved1;
487-
/*10*/ struct ocfs2_chain_rec cl_recs[0]; /* Chain records */
487+
/*10*/ struct ocfs2_chain_rec cl_recs[]; /* Chain records */
488488
};
489489

490490
/*
@@ -496,7 +496,7 @@ struct ocfs2_truncate_log {
496496
/*00*/ __le16 tl_count; /* Total records in this log */
497497
__le16 tl_used; /* Number of records in use */
498498
__le32 tl_reserved1;
499-
/*08*/ struct ocfs2_truncate_rec tl_recs[0]; /* Truncate records */
499+
/*08*/ struct ocfs2_truncate_rec tl_recs[]; /* Truncate records */
500500
};
501501

502502
/*
@@ -640,7 +640,7 @@ struct ocfs2_local_alloc
640640
__le16 la_size; /* Size of included bitmap, in bytes */
641641
__le16 la_reserved1;
642642
__le64 la_reserved2;
643-
/*10*/ __u8 la_bitmap[0];
643+
/*10*/ __u8 la_bitmap[];
644644
};
645645

646646
/*
@@ -653,7 +653,7 @@ struct ocfs2_inline_data
653653
* for data, starting at id_data */
654654
__le16 id_reserved0;
655655
__le32 id_reserved1;
656-
__u8 id_data[0]; /* Start of user data */
656+
__u8 id_data[]; /* Start of user data */
657657
};
658658

659659
/*
@@ -798,7 +798,7 @@ struct ocfs2_dx_entry_list {
798798
* possible in de_entries */
799799
__le16 de_num_used; /* Current number of
800800
* de_entries entries */
801-
struct ocfs2_dx_entry de_entries[0]; /* Indexed dir entries
801+
struct ocfs2_dx_entry de_entries[]; /* Indexed dir entries
802802
* in a packed array of
803803
* length de_num_used */
804804
};
@@ -935,7 +935,7 @@ struct ocfs2_refcount_list {
935935
__le16 rl_used; /* Current number of used records */
936936
__le32 rl_reserved2;
937937
__le64 rl_reserved1; /* Pad to sizeof(ocfs2_refcount_record) */
938-
/*10*/ struct ocfs2_refcount_rec rl_recs[0]; /* Refcount records */
938+
/*10*/ struct ocfs2_refcount_rec rl_recs[]; /* Refcount records */
939939
};
940940

941941

@@ -1021,7 +1021,7 @@ struct ocfs2_xattr_header {
10211021
buckets. A block uses
10221022
xb_check and sets
10231023
this field to zero.) */
1024-
struct ocfs2_xattr_entry xh_entries[0]; /* xattr entry list. */
1024+
struct ocfs2_xattr_entry xh_entries[]; /* xattr entry list. */
10251025
};
10261026

10271027
/*
@@ -1207,7 +1207,7 @@ struct ocfs2_local_disk_dqinfo {
12071207
/* Header of one chunk of a quota file */
12081208
struct ocfs2_local_disk_chunk {
12091209
__le32 dqc_free; /* Number of free entries in the bitmap */
1210-
__u8 dqc_bitmap[0]; /* Bitmap of entries in the corresponding
1210+
__u8 dqc_bitmap[]; /* Bitmap of entries in the corresponding
12111211
* chunk of quota file */
12121212
};
12131213

0 commit comments

Comments
 (0)