diff mbox

[Qemu-trivial,01/13] qemu-socket: zero-initialize SocketAddress

Message ID 51C4985E.1020204@msgid.tls.msk.ru
State New
Headers show

Commit Message

Michael Tokarev June 21, 2013, 6:15 p.m. UTC
21.06.2013 14:38, Gerd Hoffmann wrote:
> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
> ---
>  util/qemu-sockets.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c
> index fdd8dc4..364bd8c 100644
> --- a/util/qemu-sockets.c
> +++ b/util/qemu-sockets.c
> @@ -855,7 +855,7 @@ SocketAddress *socket_parse(const char *str, Error **errp)
>  {
>      SocketAddress *addr = NULL;
>  
> -    addr = g_new(SocketAddress, 1);
> +    addr = g_new0(SocketAddress, 1);

While at it we can remove the =NULL assignment too, guess, someting like this:


Is that okay with you? :)

Not that it matter much actually (I guess gcc may optimize it
out entirely by its own already).

And not that the original issue is a big issue really, because
in each case each relevant field is initialized.  It's still
nice to see stuff clean in debugger and other places, but the
code which actually uses this struct should work fine without
the change.

/mjt

Comments

Gerd Hoffmann June 24, 2013, 6:13 a.m. UTC | #1
On 06/21/13 20:15, Michael Tokarev wrote:
> 21.06.2013 14:38, Gerd Hoffmann wrote:
>> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
>> ---
>>  util/qemu-sockets.c |    2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c
>> index fdd8dc4..364bd8c 100644
>> --- a/util/qemu-sockets.c
>> +++ b/util/qemu-sockets.c
>> @@ -855,7 +855,7 @@ SocketAddress *socket_parse(const char *str, Error **errp)
>>  {
>>      SocketAddress *addr = NULL;
>>  
>> -    addr = g_new(SocketAddress, 1);
>> +    addr = g_new0(SocketAddress, 1);
> 
> While at it we can remove the =NULL assignment too, guess, someting like this:
> 
> --- a/util/qemu-sockets.c
> +++ b/util/qemu-sockets.c
> @@ -848,9 +848,7 @@ int unix_nonblocking_connect(const char *path,
> 
>  SocketAddress *socket_parse(const char *str, Error **errp)
>  {
> -    SocketAddress *addr = NULL;
> -
> -    addr = g_new(SocketAddress, 1);
> +    SocketAddress *addr = addr = g_new0(SocketAddress, 1);
>      if (strstart(str, "unix:", NULL)) {
>          if (str[5] == '\0') {
>              error_setg(errp, "invalid Unix socket address");
> 
> Is that okay with you? :)

Yes.

> And not that the original issue is a big issue really, because
> in each case each relevant field is initialized.

Except in the error cases.

cheers,
  Gerd
diff mbox

Patch

--- a/util/qemu-sockets.c
+++ b/util/qemu-sockets.c
@@ -848,9 +848,7 @@  int unix_nonblocking_connect(const char *path,

 SocketAddress *socket_parse(const char *str, Error **errp)
 {
-    SocketAddress *addr = NULL;
-
-    addr = g_new(SocketAddress, 1);
+    SocketAddress *addr = addr = g_new0(SocketAddress, 1);
     if (strstart(str, "unix:", NULL)) {
         if (str[5] == '\0') {
             error_setg(errp, "invalid Unix socket address");