mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-12-06 02:24:14 +08:00
2e83abdcb3
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 7649773293
("cxgb3/l2t: Fix undefined behaviour")
Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
42 lines
1016 B
C
42 lines
1016 B
C
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
/*
|
|
* Copyright (C)2003-2006 Helsinki University of Technology
|
|
* Copyright (C)2003-2006 USAGI/WIDE Project
|
|
*/
|
|
/*
|
|
* Authors:
|
|
* Noriaki TAKAMIYA @USAGI
|
|
* Masahide NAKAMURA @USAGI
|
|
* YOSHIFUJI Hideaki @USAGI
|
|
*/
|
|
#ifndef _NET_MIP6_H
|
|
#define _NET_MIP6_H
|
|
|
|
#include <linux/skbuff.h>
|
|
#include <net/sock.h>
|
|
|
|
/*
|
|
* Mobility Header
|
|
*/
|
|
struct ip6_mh {
|
|
__u8 ip6mh_proto;
|
|
__u8 ip6mh_hdrlen;
|
|
__u8 ip6mh_type;
|
|
__u8 ip6mh_reserved;
|
|
__u16 ip6mh_cksum;
|
|
/* Followed by type specific messages */
|
|
__u8 data[];
|
|
} __packed;
|
|
|
|
#define IP6_MH_TYPE_BRR 0 /* Binding Refresh Request */
|
|
#define IP6_MH_TYPE_HOTI 1 /* HOTI Message */
|
|
#define IP6_MH_TYPE_COTI 2 /* COTI Message */
|
|
#define IP6_MH_TYPE_HOT 3 /* HOT Message */
|
|
#define IP6_MH_TYPE_COT 4 /* COT Message */
|
|
#define IP6_MH_TYPE_BU 5 /* Binding Update */
|
|
#define IP6_MH_TYPE_BACK 6 /* Binding ACK */
|
|
#define IP6_MH_TYPE_BERROR 7 /* Binding Error */
|
|
#define IP6_MH_TYPE_MAX IP6_MH_TYPE_BERROR
|
|
|
|
#endif
|