block: Simplify QAPI_LIST_ADD
authorEric Blake <eblake@redhat.com>
Tue, 27 Oct 2020 05:05:46 +0000 (00:05 -0500)
committerEric Blake <eblake@redhat.com>
Fri, 30 Oct 2020 20:10:14 +0000 (15:10 -0500)
There is no need to rely on the verbosity of the gcc/clang compiler
extension of g_new(typeof(X), 1) when we can instead use the standard
g_malloc(sizeof(X)).  In general, we like g_new over g_malloc for
returning type X rather than void* to let the compiler catch more
potential typing mistakes, but in this particular macro, our other use
of typeof on the same line already ensures we are getting correct
results.

Suggested-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <20201027050556.269064-2-eblake@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
block.c

diff --git a/block.c b/block.c
index ee5b28a9798d1c7745ac82753db67d1a501a2390..dd551d7ea92b9c82876c0f9f07a6f9c5f6e0bc84 100644 (file)
--- a/block.c
+++ b/block.c
@@ -5240,7 +5240,7 @@ BlockDeviceInfoList *bdrv_named_nodes_list(bool flat,
 }
 
 #define QAPI_LIST_ADD(list, element) do { \
-    typeof(list) _tmp = g_new(typeof(*(list)), 1); \
+    typeof(list) _tmp = g_malloc(sizeof(*(list))); \
     _tmp->value = (element); \
     _tmp->next = (list); \
     (list) = _tmp; \