hw/i386/fw_cfg: Use g_new() and g_new0() instead of g_malloc()
Replace g_malloc() and g_malloc0() calls that calculate the allocation size using sizeof() with the type-safe g_new() and g_new0() macros. This aligns the code with QEMU's coding style guidelines, improving readability and protecting against potential integer overflow vulnerabilities when allocating arrays. Signed-off-by: Sourish Duttta Sharma <sourishduttasharma770@gmail.com> Message-ID: <20260224160020.137036-1-sourishduttasharma770@gmail.com> Signed-off-by: Thomas Huth <thuth@redhat.com>
Sourish Dutta Sharma committed
Feb 24, 2026 at 16:00 UTC
0f25e8a5e6ce86f565c7bcfd233ebabec5bfc378
1 file changed
+2
-2
hw/i386/fw_cfg.c
+2
-2
@@ -91,7 +91,7 @@ void fw_cfg_build_smbios(PCMachineState *pcms, FWCfgState *fw_cfg,
91
92
/* build the array of physical mem area from e820 table */
93
nr_e820 = e820_get_table(NULL);
94
- mem_array = g_malloc0(sizeof(*mem_array) * nr_e820);
94
+ mem_array = g_new0(struct smbios_phys_mem_area, nr_e820);
95
for (i = 0, array_count = 0; i < nr_e820; i++) {
96
uint64_t addr, len;
97
@@ -207,7 +207,7 @@ void fw_cfg_build_feature_control(MachineState *ms, FWCfgState *fw_cfg)
207
return;
208
}
209
210
- val = g_malloc(sizeof(*val));
210
+ val = g_new(uint64_t, 1);
211
*val = cpu_to_le64(feature_control_bits | FEATURE_CONTROL_LOCKED);
212
fw_cfg_add_file(fw_cfg, "etc/msr_feature_control", val, sizeof(*val));
213
}