[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 3/3] Use g_new() & friends where that makes obvious sense
- To: Markus Armbruster <armbru@xxxxxxxxxx>
- From: Eric Blake <eblake@xxxxxxxxxx>
- Date: Tue, 15 Mar 2022 04:07:48 -0500
- Cc: qemu-devel@xxxxxxxxxx, Paolo Bonzini <pbonzini@xxxxxxxxxx>, Richard Henderson <richard.henderson@xxxxxxxxxx>, Gerd Hoffmann <kraxel@xxxxxxxxxx>, Christian Schoenebeck <qemu_oss@xxxxxxxxxxxxx>, "Gonglei (Arei)" <arei.gonglei@xxxxxxxxxx>, Marc-André Lureau <marcandre.lureau@xxxxxxxxxx>, "Michael S. Tsirkin" <mst@xxxxxxxxxx>, Igor Mammedov <imammedo@xxxxxxxxxx>, Ani Sinha <ani@xxxxxxxxxxx>, Laurent Vivier <lvivier@xxxxxxxxxx>, Amit Shah <amit@xxxxxxxxxx>, Peter Maydell <peter.maydell@xxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Anthony Perard <anthony.perard@xxxxxxxxxx>, Paul Durrant <paul@xxxxxxx>, Hervé Poussineau <hpoussin@xxxxxxxxxxx>, Aleksandar Rikalo <aleksandar.rikalo@xxxxxxxxxx>, Corey Minyard <cminyard@xxxxxxxxxx>, Patrick Venture <venture@xxxxxxxxxx>, Eduardo Habkost <eduardo@xxxxxxxxxxx>, Marcel Apfelbaum <marcel.apfelbaum@xxxxxxxxx>, Peter Xu <peterx@xxxxxxxxxx>, Jason Wang <jasowang@xxxxxxxxxx>, Cédric Le Goater <clg@xxxxxxxx>, Daniel Henrique Barboza <danielhb413@xxxxxxxxx>, David Gibson <david@xxxxxxxxxxxxxxxxxxxxx>, Greg Kurz <groug@xxxxxxxx>, Philippe Mathieu-Daudé <f4bug@xxxxxxxxx>, Jean-Christophe Dubois <jcd@xxxxxxxxxxxxxxx>, Keith Busch <kbusch@xxxxxxxxxx>, Klaus Jensen <its@xxxxxxxxxxxxx>, Yuval Shaia <yuval.shaia.ml@xxxxxxxxx>, Yoshinori Sato <ysato@xxxxxxxxxxxxxxxxxxxx>, Magnus Damm <magnus.damm@xxxxxxxxx>, Fabien Chouteau <chouteau@xxxxxxxxxxx>, KONRAD Frederic <frederic.konrad@xxxxxxxxxxx>, Mark Cave-Ayland <mark.cave-ayland@xxxxxxxxxxxx>, Artyom Tarasenko <atar4qemu@xxxxxxxxx>, Alex Williamson <alex.williamson@xxxxxxxxxx>, Eric Auger <eric.auger@xxxxxxxxxx>, Max Filippov <jcmvbkbc@xxxxxxxxx>, Juan Quintela <quintela@xxxxxxxxxx>, "Dr. David Alan Gilbert" <dgilbert@xxxxxxxxxx>, Konstantin Kostiuk <kkostiuk@xxxxxxxxxx>, Michael Roth <michael.roth@xxxxxxx>, Daniel P. Berrangé <berrange@xxxxxxxxxx>, Pavel Dovgalyuk <pavel.dovgaluk@xxxxxxxxx>, Alex Bennée <alex.bennee@xxxxxxxxxx>, David Hildenbrand <david@xxxxxxxxxx>, Wenchao Wang <wenchao.wang@xxxxxxxxx>, Colin Xu <colin.xu@xxxxxxxxx>, Kamil Rytarowski <kamil@xxxxxxxxxx>, Reinoud Zandijk <reinoud@xxxxxxxxxx>, Sunil Muthuswamy <sunilmut@xxxxxxxxxxxxx>, Cornelia Huck <cohuck@xxxxxxxxxx>, Thomas Huth <thuth@xxxxxxxxxx>, Vladimir Sementsov-Ogievskiy <vsementsov@xxxxxxxxxxxxx>, John Snow <jsnow@xxxxxxxxxx>, kvm@xxxxxxxxxxxxxxx, qemu-arm@xxxxxxxxxx, xen-devel@xxxxxxxxxxxxxxxxxxxx, qemu-ppc@xxxxxxxxxx, qemu-block@xxxxxxxxxx, haxm-team@xxxxxxxxx, qemu-s390x@xxxxxxxxxx
- Delivery-date: Tue, 15 Mar 2022 09:08:18 +0000
- List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
On Mon, Mar 14, 2022 at 05:01:08PM +0100, Markus Armbruster wrote:
> 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).
>
> Patch created mechanically with:
>
> $ spatch --in-place --sp-file scripts/coccinelle/use-g_new-etc.cocci \
> --macro-file scripts/cocci-macro-file.h FILES...
>
> Signed-off-by: Markus Armbruster <armbru@xxxxxxxxxx>
> ---
I agree that this is mechanical, but...
<snip>
> qga/commands-win32.c | 8 ++---
> qga/commands.c | 2 +-
> qom/qom-qmp-cmds.c | 2 +-
> replay/replay-char.c | 4 +--
> replay/replay-events.c | 10 +++---
> scripts/coverity-scan/model.c | 2 +-
...are we sure we want to touch this particular file?
> diff --git a/scripts/coverity-scan/model.c b/scripts/coverity-scan/model.c
> index 9d4fba53d9..30bea672e1 100644
> --- a/scripts/coverity-scan/model.c
> +++ b/scripts/coverity-scan/model.c
> @@ -356,7 +356,7 @@ int g_poll (GPollFD *fds, unsigned nfds, int timeout)
> typedef struct _GIOChannel GIOChannel;
> GIOChannel *g_io_channel_unix_new(int fd)
> {
> - GIOChannel *c = g_malloc0(sizeof(GIOChannel));
> + GIOChannel *c = g_new0(GIOChannel, 1);
> __coverity_escape__(fd);
> return c;
> }
Our model has a definition of g_malloc0(), but I'm not sure whether
Coverity picks up the macro g_new0() in the same manner.
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org
|