mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-08 10:13:56 -06:00
misc: Replace zero-length arrays with flexible array member (automatic)
Description copied from Linux kernel commit from Gustavo A. R. Silva
(see [3]):
--v-- description start --v--
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], 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 unadvertenly introduced [2] to the
Linux codebase from now on.
--^-- description end --^--
Do the similar housekeeping in the QEMU codebase (which uses
C99 since commit 7be41675f7
).
All these instances of code were found with the help of the
following Coccinelle script:
@@
identifier s, m, a;
type t, T;
@@
struct s {
...
t m;
- T a[0];
+ T a[];
};
@@
identifier s, m, a;
type t, T;
@@
struct s {
...
t m;
- T a[0];
+ T a[];
} QEMU_PACKED;
[1] https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html
[2] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=76497732932f
[3] https://git.kernel.org/pub/scm/linux/kernel/git/gustavoars/linux.git/commit/?id=17642a2fbd2c1
Inspired-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
Reviewed-by: David Hildenbrand <david@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
770275ed0c
commit
f7795e4096
24 changed files with 35 additions and 34 deletions
|
@ -485,7 +485,7 @@ struct NvdimmFuncGetLabelDataOut {
|
|||
/* the size of buffer filled by QEMU. */
|
||||
uint32_t len;
|
||||
uint32_t func_ret_status; /* return status code. */
|
||||
uint8_t out_buf[0]; /* the data got via Get Namesapce Label function. */
|
||||
uint8_t out_buf[]; /* the data got via Get Namesapce Label function. */
|
||||
} QEMU_PACKED;
|
||||
typedef struct NvdimmFuncGetLabelDataOut NvdimmFuncGetLabelDataOut;
|
||||
QEMU_BUILD_BUG_ON(sizeof(NvdimmFuncGetLabelDataOut) > NVDIMM_DSM_MEMORY_SIZE);
|
||||
|
@ -493,7 +493,7 @@ QEMU_BUILD_BUG_ON(sizeof(NvdimmFuncGetLabelDataOut) > NVDIMM_DSM_MEMORY_SIZE);
|
|||
struct NvdimmFuncSetLabelDataIn {
|
||||
uint32_t offset; /* the offset in the namespace label data area. */
|
||||
uint32_t length; /* the size of data is to be written via the function. */
|
||||
uint8_t in_buf[0]; /* the data written to label data area. */
|
||||
uint8_t in_buf[]; /* the data written to label data area. */
|
||||
} QEMU_PACKED;
|
||||
typedef struct NvdimmFuncSetLabelDataIn NvdimmFuncSetLabelDataIn;
|
||||
QEMU_BUILD_BUG_ON(sizeof(NvdimmFuncSetLabelDataIn) +
|
||||
|
@ -510,7 +510,7 @@ struct NvdimmFuncReadFITOut {
|
|||
/* the size of buffer filled by QEMU. */
|
||||
uint32_t len;
|
||||
uint32_t func_ret_status; /* return status code. */
|
||||
uint8_t fit[0]; /* the FIT data. */
|
||||
uint8_t fit[]; /* the FIT data. */
|
||||
} QEMU_PACKED;
|
||||
typedef struct NvdimmFuncReadFITOut NvdimmFuncReadFITOut;
|
||||
QEMU_BUILD_BUG_ON(sizeof(NvdimmFuncReadFITOut) > NVDIMM_DSM_MEMORY_SIZE);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue