]> git.ipfire.org Git - thirdparty/qemu.git/commit
9pfs: Use g_new() & friends where that makes obvious sense
authorMarkus Armbruster <armbru@redhat.com>
Tue, 15 Mar 2022 14:41:55 +0000 (15:41 +0100)
committerMarkus Armbruster <armbru@redhat.com>
Mon, 21 Mar 2022 14:44:44 +0000 (15:44 +0100)
commit1366244ab6d0c83bf0f90270e5bb608651a3cc8f
treee315609c3297e701b93bff8e7d5fd7bcaf3e94c5
parent15ba4a9f7ba592f2f1a0eb50b20f0ebd4412ab6e
9pfs: Use g_new() & friends where that makes obvious sense

g_new(T, n) is neater than g_malloc(sizeof(T) * n).  It's also safer,
for two reasons.  One, it catches multiplication overflowing size_t.
Two, it returns T * rather than void *, which lets the compiler catch
more type errors.

This commit only touches allocations with size arguments of the form
sizeof(T).

Initial patch created mechanically with:

    $ spatch --in-place --sp-file scripts/coccinelle/use-g_new-etc.cocci \
     --macro-file scripts/cocci-macro-file.h FILES...

This uncovers a typing error:

    ../hw/9pfs/9p.c: In function ‘qid_path_fullmap’:
    ../hw/9pfs/9p.c:855:13: error: assignment to ‘QpfEntry *’ from incompatible pointer type ‘QppEntry *’ [-Werror=incompatible-pointer-types]
      855 |         val = g_new0(QppEntry, 1);
  |             ^

Harmless, because QppEntry is larger than QpfEntry.  Manually fixed to
allocate a QpfEntry instead.

Cc: Greg Kurz <groug@kaod.org>
Cc: Christian Schoenebeck <qemu_oss@crudebyte.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Reviewed-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Greg Kurz <groug@kaod.org>
Message-Id: <20220315144156.1595462-3-armbru@redhat.com>
hw/9pfs/9p-proxy.c
hw/9pfs/9p-synth.c
hw/9pfs/9p.c
hw/9pfs/codir.c
tests/qtest/virtio-9p-test.c