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-- 4.0 KB
Makefile -rw-r--r-- 1.3 KB
bat_algo.c -rw-r--r-- 5.6 KB
bat_algo.h -rw-r--r-- 755 bytes
bat_iv_ogm.c -rw-r--r-- 79.6 KB
bat_iv_ogm.h -rw-r--r-- 303 bytes
bat_v.c -rw-r--r-- 29.9 KB
bat_v.h -rw-r--r-- 827 bytes
bat_v_elp.c -rw-r--r-- 17.2 KB
bat_v_elp.h -rw-r--r-- 832 bytes
bat_v_ogm.c -rw-r--r-- 32.6 KB
bat_v_ogm.h -rw-r--r-- 925 bytes
bitarray.c -rw-r--r-- 2.6 KB
bitarray.h -rw-r--r-- 1.5 KB
bridge_loop_avoidance.c -rw-r--r-- 69.7 KB
bridge_loop_avoidance.h -rw-r--r-- 3.9 KB
debugfs.c -rw-r--r-- 12.3 KB
debugfs.h -rw-r--r-- 1.6 KB
distributed-arp-table.c -rw-r--r-- 52.1 KB
distributed-arp-table.h -rw-r--r-- 4.9 KB
fragmentation.c -rw-r--r-- 15.6 KB
fragmentation.h -rw-r--r-- 1.3 KB
gateway_client.c -rw-r--r-- 22.2 KB
gateway_client.h -rw-r--r-- 1.7 KB
gateway_common.c -rw-r--r-- 7.3 KB
gateway_common.h -rw-r--r-- 1.0 KB
hard-interface.c -rw-r--r-- 29.4 KB
hard-interface.h -rw-r--r-- 3.9 KB
hash.c -rw-r--r-- 1.7 KB
hash.h -rw-r--r-- 3.9 KB
icmp_socket.c -rw-r--r-- 10.0 KB
icmp_socket.h -rw-r--r-- 745 bytes
log.c -rw-r--r-- 5.3 KB
log.h -rw-r--r-- 4.0 KB
main.c -rw-r--r-- 20.3 KB
main.h -rw-r--r-- 12.3 KB
multicast.c -rw-r--r-- 72.0 KB
multicast.h -rw-r--r-- 2.5 KB
netlink.c -rw-r--r-- 40.7 KB
netlink.h -rw-r--r-- 955 bytes
network-coding.c -rw-r--r-- 58.0 KB
network-coding.h -rw-r--r-- 3.1 KB
originator.c -rw-r--r-- 41.7 KB
originator.h -rw-r--r-- 3.2 KB
routing.c -rw-r--r-- 36.6 KB
routing.h -rw-r--r-- 1.7 KB
send.c -rw-r--r-- 29.6 KB
send.h -rw-r--r-- 4.2 KB
soft-interface.c -rw-r--r-- 31.2 KB
soft-interface.h -rw-r--r-- 1.1 KB
sysfs.c -rw-r--r-- 35.2 KB
sysfs.h -rw-r--r-- 2.3 KB
tp_meter.c -rw-r--r-- 42.3 KB
tp_meter.h -rw-r--r-- 629 bytes
trace.c -rw-r--r-- 164 bytes
trace.h -rw-r--r-- 1.7 KB
translation-table.c -rw-r--r-- 132.8 KB
translation-table.h -rw-r--r-- 2.6 KB
tvlv.c -rw-r--r-- 18.7 KB
tvlv.h -rw-r--r-- 1.7 KB
types.h -rw-r--r-- 62.5 KB

back to top