qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH 36/88] SLIRP: use g_new() family of functions


From: Samuel Thibault
Subject: Re: [Qemu-devel] [PATCH 36/88] SLIRP: use g_new() family of functions
Date: Mon, 9 Oct 2017 00:20:58 +0200
User-agent: NeoMutt/20170113 (1.7.2)

Hello,

Philippe Mathieu-Daudé, on ven. 06 oct. 2017 20:49:31 -0300, wrote:
> --- a/net/slirp.c
> +++ b/net/slirp.c
> @@ -869,7 +869,7 @@ net_init_slirp_configs(const StringList *fwd, int flags)
>      while (fwd) {
>          struct slirp_config_str *config;
>  
> -        config = g_malloc0(sizeof(*config));
> +        config = g_new0(struct slirp_config_str, 1);

It doesn't really seem like an improvement to me in such case: we don't
have overflow issues here, and using sizeof(*config) makes the line
clearly correct, while expliciting the struct behind means we need to
make sure of the coherency.

> diff --git a/slirp/socket.c b/slirp/socket.c
> index cb7b5b608d..2eccb68c2e 100644
> --- a/slirp/socket.c
> +++ b/slirp/socket.c
> @@ -48,7 +48,7 @@ socreate(Slirp *slirp)
>  {
>    struct socket *so;
>  
> -  so = (struct socket *)malloc(sizeof(struct socket));
> +  so = g_new(struct socket, 1);

Similarly, here I'd rather write g_malloc(sizeof(*so));

Samuel



reply via email to

[Prev in Thread] Current Thread [Next in Thread]