mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-05 16:53:55 -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
|
@ -518,7 +518,7 @@ struct AcpiDmarDeviceScope {
|
|||
struct {
|
||||
uint8_t device;
|
||||
uint8_t function;
|
||||
} path[0];
|
||||
} path[];
|
||||
} QEMU_PACKED;
|
||||
typedef struct AcpiDmarDeviceScope AcpiDmarDeviceScope;
|
||||
|
||||
|
@ -530,7 +530,7 @@ struct AcpiDmarHardwareUnit {
|
|||
uint8_t reserved;
|
||||
uint16_t pci_segment; /* The PCI Segment associated with this unit */
|
||||
uint64_t address; /* Base address of remapping hardware register-set */
|
||||
AcpiDmarDeviceScope scope[0];
|
||||
AcpiDmarDeviceScope scope[];
|
||||
} QEMU_PACKED;
|
||||
typedef struct AcpiDmarHardwareUnit AcpiDmarHardwareUnit;
|
||||
|
||||
|
@ -541,7 +541,7 @@ struct AcpiDmarRootPortATS {
|
|||
uint8_t flags;
|
||||
uint8_t reserved;
|
||||
uint16_t pci_segment;
|
||||
AcpiDmarDeviceScope scope[0];
|
||||
AcpiDmarDeviceScope scope[];
|
||||
} QEMU_PACKED;
|
||||
typedef struct AcpiDmarRootPortATS AcpiDmarRootPortATS;
|
||||
|
||||
|
@ -604,7 +604,7 @@ typedef struct AcpiIortMemoryAccess AcpiIortMemoryAccess;
|
|||
struct AcpiIortItsGroup {
|
||||
ACPI_IORT_NODE_HEADER_DEF
|
||||
uint32_t its_count;
|
||||
uint32_t identifiers[0];
|
||||
uint32_t identifiers[];
|
||||
} QEMU_PACKED;
|
||||
typedef struct AcpiIortItsGroup AcpiIortItsGroup;
|
||||
|
||||
|
@ -621,7 +621,7 @@ struct AcpiIortSmmu3 {
|
|||
uint32_t pri_gsiv;
|
||||
uint32_t gerr_gsiv;
|
||||
uint32_t sync_gsiv;
|
||||
AcpiIortIdMapping id_mapping_array[0];
|
||||
AcpiIortIdMapping id_mapping_array[];
|
||||
} QEMU_PACKED;
|
||||
typedef struct AcpiIortSmmu3 AcpiIortSmmu3;
|
||||
|
||||
|
@ -630,7 +630,7 @@ struct AcpiIortRC {
|
|||
AcpiIortMemoryAccess memory_properties;
|
||||
uint32_t ats_attribute;
|
||||
uint32_t pci_segment_number;
|
||||
AcpiIortIdMapping id_mapping_array[0];
|
||||
AcpiIortIdMapping id_mapping_array[];
|
||||
} QEMU_PACKED;
|
||||
typedef struct AcpiIortRC AcpiIortRC;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue