https://github.com/torvalds/linux
Revision e76018cb604ace486de9cf85898c14bb2b47faff authored by Gustavo A. R. Silva on 23 March 2020, 21:48:10 UTC, committed by Gustavo A. R. Silva on 18 April 2020, 20:44:54 UTC
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://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html
[2] https://github.com/KSPP/linux/issues/21
[3] commit 76497732932f ("cxgb3/l2t: Fix undefined behaviour")

Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
1 parent 5a58ec8
History
Tip revision: e76018cb604ace486de9cf85898c14bb2b47faff authored by Gustavo A. R. Silva on 23 March 2020, 21:48:10 UTC
can: dev: peak_canfd.h: Replace zero-length array with flexible-array member
Tip revision: e76018c
File Mode Size
Kconfig -rw-r--r-- 30.5 KB
Makefile -rw-r--r-- 3.4 KB
act_api.c -rw-r--r-- 39.1 KB
act_bpf.c -rw-r--r-- 10.4 KB
act_connmark.c -rw-r--r-- 6.5 KB
act_csum.c -rw-r--r-- 16.8 KB
act_ct.c -rw-r--r-- 37.7 KB
act_ctinfo.c -rw-r--r-- 10.8 KB
act_gact.c -rw-r--r-- 7.4 KB
act_ife.c -rw-r--r-- 20.5 KB
act_ipt.c -rw-r--r-- 10.6 KB
act_meta_mark.c -rw-r--r-- 1.7 KB
act_meta_skbprio.c -rw-r--r-- 1.7 KB
act_meta_skbtcindex.c -rw-r--r-- 1.8 KB
act_mirred.c -rw-r--r-- 12.0 KB
act_mpls.c -rw-r--r-- 10.6 KB
act_nat.c -rw-r--r-- 7.8 KB
act_pedit.c -rw-r--r-- 12.0 KB
act_police.c -rw-r--r-- 10.7 KB
act_sample.c -rw-r--r-- 8.2 KB
act_simple.c -rw-r--r-- 6.4 KB
act_skbedit.c -rw-r--r-- 10.2 KB
act_skbmod.c -rw-r--r-- 8.0 KB
act_tunnel_key.c -rw-r--r-- 22.0 KB
act_vlan.c -rw-r--r-- 9.1 KB
cls_api.c -rw-r--r-- 92.7 KB
cls_basic.c -rw-r--r-- 7.9 KB
cls_bpf.c -rw-r--r-- 16.9 KB
cls_cgroup.c -rw-r--r-- 5.0 KB
cls_flow.c -rw-r--r-- 16.5 KB
cls_flower.c -rw-r--r-- 82.1 KB
cls_fw.c -rw-r--r-- 9.7 KB
cls_matchall.c -rw-r--r-- 10.2 KB
cls_route.c -rw-r--r-- 14.4 KB
cls_rsvp.c -rw-r--r-- 547 bytes
cls_rsvp.h -rw-r--r-- 17.9 KB
cls_rsvp6.c -rw-r--r-- 554 bytes
cls_tcindex.c -rw-r--r-- 17.4 KB
cls_u32.c -rw-r--r-- 33.2 KB
em_canid.c -rw-r--r-- 5.3 KB
em_cmp.c -rw-r--r-- 1.9 KB
em_ipset.c -rw-r--r-- 2.9 KB
em_ipt.c -rw-r--r-- 6.7 KB
em_meta.c -rw-r--r-- 22.8 KB
em_nbyte.c -rw-r--r-- 1.6 KB
em_text.c -rw-r--r-- 3.4 KB
em_u32.c -rw-r--r-- 1.2 KB
ematch.c -rw-r--r-- 14.5 KB
sch_api.c -rw-r--r-- 54.4 KB
sch_atm.c -rw-r--r-- 19.5 KB
sch_blackhole.c -rw-r--r-- 924 bytes
sch_cake.c -rw-r--r-- 77.3 KB
sch_cbq.c -rw-r--r-- 42.1 KB
sch_cbs.c -rw-r--r-- 13.7 KB
sch_choke.c -rw-r--r-- 12.6 KB
sch_codel.c -rw-r--r-- 8.5 KB
sch_drr.c -rw-r--r-- 11.2 KB
sch_dsmark.c -rw-r--r-- 11.9 KB
sch_etf.c -rw-r--r-- 11.6 KB
sch_ets.c -rw-r--r-- 19.8 KB
sch_fifo.c -rw-r--r-- 5.9 KB
sch_fq.c -rw-r--r-- 24.5 KB
sch_fq_codel.c -rw-r--r-- 18.7 KB
sch_fq_pie.c -rw-r--r-- 14.4 KB
sch_generic.c -rw-r--r-- 32.8 KB
sch_gred.c -rw-r--r-- 22.3 KB
sch_hfsc.c -rw-r--r-- 39.5 KB
sch_hhf.c -rw-r--r-- 21.5 KB
sch_htb.c -rw-r--r-- 41.5 KB
sch_ingress.c -rw-r--r-- 7.5 KB
sch_mq.c -rw-r--r-- 7.1 KB
sch_mqprio.c -rw-r--r-- 16.6 KB
sch_multiq.c -rw-r--r-- 8.8 KB
sch_netem.c -rw-r--r-- 31.1 KB
sch_pie.c -rw-r--r-- 14.9 KB
sch_plug.c -rw-r--r-- 6.4 KB
sch_prio.c -rw-r--r-- 9.7 KB
sch_qfq.c -rw-r--r-- 41.6 KB
sch_red.c -rw-r--r-- 11.8 KB
sch_sfb.c -rw-r--r-- 16.8 KB
sch_sfq.c -rw-r--r-- 22.3 KB
sch_skbprio.c -rw-r--r-- 7.5 KB
sch_taprio.c -rw-r--r-- 48.6 KB
sch_tbf.c -rw-r--r-- 14.8 KB
sch_teql.c -rw-r--r-- 11.8 KB

back to top