[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-trivial] [PULL 05/22] HACKING: document preference for g_new inste
From: |
Michael Tokarev |
Subject: |
[Qemu-trivial] [PULL 05/22] HACKING: document preference for g_new instead of g_malloc |
Date: |
Sun, 20 May 2018 09:14:51 +0300 |
From: Murilo Opsfelder Araujo <address@hidden>
This patch documents the preference for g_new instead of g_malloc. The
reasons were adapted from commit b45c03f585ea9bb1af76c73e82195418c294919d.
Discussion in QEMU's mailing list:
http://lists.nongnu.org/archive/html/qemu-devel/2018-05/msg03238.html
Cc: address@hidden
Cc: David Hildenbrand <address@hidden>
Cc: Eduardo Habkost <address@hidden>
Cc: Markus Armbruster <address@hidden>
Cc: Paolo Bonzini <address@hidden>
Signed-off-by: Murilo Opsfelder Araujo <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
Reviewed-by: Alex Bennée <address@hidden>
Reviewed-by: David Hildenbrand <address@hidden>
Signed-off-by: Michael Tokarev <address@hidden>
---
HACKING | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/HACKING b/HACKING
index 4125c97d8d..0fc3e0fc04 100644
--- a/HACKING
+++ b/HACKING
@@ -118,6 +118,15 @@ Please note that g_malloc will exit on allocation failure,
so there
is no need to test for failure (as you would have to with malloc).
Calling g_malloc with a zero size is valid and will return NULL.
+Prefer g_new(T, n) instead of g_malloc(sizeof(T) * n) for the following
+reasons:
+
+ a. It catches multiplication overflowing size_t;
+ b. It returns T * instead of void *, letting compiler catch more type
+ errors.
+
+Declarations like T *v = g_malloc(sizeof(*v)) are acceptable, though.
+
Memory allocated by qemu_memalign or qemu_blockalign must be freed with
qemu_vfree, since breaking this will cause problems on Win32.
--
2.11.0
- [Qemu-trivial] [PULL 15/22] hw/timer/mt48t59: Fix bit-rotten NVRAM_PRINTF format strings, (continued)
- [Qemu-trivial] [PULL 15/22] hw/timer/mt48t59: Fix bit-rotten NVRAM_PRINTF format strings, Michael Tokarev, 2018/05/20
- [Qemu-trivial] [PULL 06/22] qemu-img-commands.hx: argument ordering fixups, Michael Tokarev, 2018/05/20
- [Qemu-trivial] [PULL 20/22] gdbstub: Handle errors in gdb_accept(), Michael Tokarev, 2018/05/20
- [Qemu-trivial] [PULL 08/22] qemu-img: remove references to GEN_DOCS, Michael Tokarev, 2018/05/20
- [Qemu-trivial] [PULL 07/22] qemu-img.texi: fix command ordering, Michael Tokarev, 2018/05/20
- [Qemu-trivial] [PULL 22/22] acpi: fix a comment about aml_call0(), Michael Tokarev, 2018/05/20
- [Qemu-trivial] [PULL 10/22] qemu-img-cmds.hx: add passive-aggressive note, Michael Tokarev, 2018/05/20
- [Qemu-trivial] [PULL 21/22] qapi/net.json: Fix the version number of the "vlan" removal, Michael Tokarev, 2018/05/20
- [Qemu-trivial] [PULL 05/22] HACKING: document preference for g_new instead of g_malloc,
Michael Tokarev <=
- [Qemu-trivial] [PULL 09/22] qemu-img: Make documentation between .texi and .hx consistent, Michael Tokarev, 2018/05/20
- [Qemu-trivial] [PULL 16/22] qemu-options: Allow -no-user-config again, Michael Tokarev, 2018/05/20
- [Qemu-trivial] [PULL 11/22] hw/ide/ahci: Keep ALLWINNER_AHCI() macro internal, Michael Tokarev, 2018/05/20
- [Qemu-trivial] [PULL 12/22] tests: fix tpm-crb tpm-tis tests race, Michael Tokarev, 2018/05/20
- [Qemu-trivial] [PULL 19/22] gdbstub: Use qemu_set_cloexec(), Michael Tokarev, 2018/05/20
- [Qemu-trivial] [PULL 18/22] replace functions which are only available in glib-2.24, Michael Tokarev, 2018/05/20
- [Qemu-trivial] [PULL 14/22] Remove unnecessary variables for function return value, Michael Tokarev, 2018/05/20
- Re: [Qemu-trivial] [Qemu-devel] [PULL 00/22] Trivial patches for 2018-05-20, Peter Maydell, 2018/05/21