lib: use struct zero initializer instead of memset

This is a more concise approach and guarantees there is
no time window where the struct is uninitialized.

Generated using the following semantic patch:

  @@
  type T;
  identifier X;
  @@
  -  T X;
  +  T X = { 0 };
     ... when exists
  (
  -  memset(&X, 0, sizeof(X));
  |
  -  memset(&X, 0, sizeof(T));
  )

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Claudio Fontana <cfontana@suse.de>
This commit is contained in:
Michal Privoznik
2023-08-02 10:09:52 +02:00
parent 7ce0fbccf1
commit b20a5e9a4d
65 changed files with 195 additions and 483 deletions

View File

@@ -484,13 +484,12 @@ aiforaf(const char *name, int af, struct addrinfo *pai, struct addrinfo **aip)
struct sockaddr sa;
struct sockaddr_in sin;
struct sockaddr_in6 sin6;
} sa;
} sa = { 0 };
socklen_t salen;
void *address = *addrList;
char host[NI_MAXHOST];
char port[NI_MAXSERV];
memset(&sa, 0, sizeof(sa));
if (resolved.h_addrtype == AF_INET) {
sa.sin.sin_family = AF_INET;
memcpy(&sa.sin.sin_addr.s_addr,