]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
lib: Finish using struct zero initializer manually
authorMichal Privoznik <mprivozn@redhat.com>
Thu, 3 Aug 2023 09:48:30 +0000 (11:48 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Thu, 3 Aug 2023 14:41:19 +0000 (16:41 +0200)
There are some cases left after previous commit which were not
picked up by coccinelle. Mostly, becuase the spatch was not
generic enough. We are left with cases like: two variables
declared on one line, a variable declared in #ifdef-s (there are
notoriously difficult for coccinelle), arrays, macro definitions,
etc.

Finish what coccinelle started, by hand.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Claudio Fontana <cfontana@suse.de>
src/libxl/libxl_capabilities.c
src/qemu/qemu_monitor.c
src/rpc/virnettlscontext.c
src/util/virnetlink.c
src/util/virutil.c
src/vmx/vmx.c
tests/libxlmock.c
tests/qemumonitorjsontest.c
tests/sockettest.c
tools/nss/libvirt_nss.c
tools/virsh-domain.c

index 5ee6fe3f67c58392849777be94e5a5a11b57b83f..177e8b988e77b4b863cb2ec13895466a9bd1e86f 100644 (file)
@@ -328,11 +328,9 @@ libxlCapsInitGuests(libxl_ctx *ctx, virCaps *caps)
     char *saveptr = NULL;
     size_t i;
 
-    struct guest_arch guest_archs[32];
+    struct guest_arch guest_archs[32] = { 0 };
     int nr_guest_archs = 0;
 
-    memset(guest_archs, 0, sizeof(guest_archs));
-
     if ((ver_info = libxl_get_version_info(ctx)) == NULL) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("Failed to get version info from libxenlight"));
index db34b6c1791603d4060998b93774ff4744d49da3..02da1d6dfc94b0601bfda0954792f23998b2b8de 100644 (file)
@@ -311,11 +311,9 @@ qemuMonitorIOWriteWithFD(qemuMonitor *mon,
     struct msghdr msg = { 0 };
     struct iovec iov[1];
     int ret;
-    char control[CMSG_SPACE(sizeof(int))];
+    char control[CMSG_SPACE(sizeof(int))] = { 0 };
     struct cmsghdr *cmsg;
 
-    memset(control, 0, sizeof(control));
-
     iov[0].iov_base = (void *)data;
     iov[0].iov_len = len;
 
index f72597ee80d72c86ce0a96098a5e626c0b06ab88..1939fe5d6e677fcf7e9c067ad7cd693540b9750c 100644 (file)
@@ -545,12 +545,11 @@ static int virNetTLSContextSanityCheckCredentials(bool isServer,
                                                   const char *certFile)
 {
     gnutls_x509_crt_t cert = NULL;
-    gnutls_x509_crt_t cacerts[MAX_CERTS];
+    gnutls_x509_crt_t cacerts[MAX_CERTS] = { 0 };
     size_t ncacerts = 0;
     size_t i;
     int ret = -1;
 
-    memset(cacerts, 0, sizeof(cacerts));
     if ((access(certFile, R_OK) == 0) &&
         !(cert = virNetTLSContextLoadCertFromFile(certFile, isServer)))
         goto cleanup;
index d964c439b4f02d917445a6fc680e2a2309e30567..2d052cd03ec764cc0a0d6cc34efb8fe12396dce8 100644 (file)
@@ -250,7 +250,7 @@ virNetlinkSendRequest(struct nl_msg *nl_msg, uint32_t src_pid,
     int fd;
     int n;
     virNetlinkHandle *nlhandle = NULL;
-    struct pollfd fds[1];
+    struct pollfd fds[1] = { 0 };
     struct nlmsghdr *nlmsg = nlmsg_hdr(nl_msg);
 
     if (protocol >= MAX_LINKS) {
@@ -286,8 +286,6 @@ virNetlinkSendRequest(struct nl_msg *nl_msg, uint32_t src_pid,
         goto error;
     }
 
-    memset(fds, 0, sizeof(fds));
-
     fds[0].fd = fd;
     fds[0].events = POLLIN;
 
index 40ca2055957b6ed7a4d6a5790b96d4ee8d84eb78..b5b65fb415fa8d9fa3896d64cb1fab9e7a719509 100644 (file)
@@ -428,7 +428,8 @@ virGetHostnameImpl(bool quiet)
 {
     int r;
     char hostname[HOST_NAME_MAX+1], *result = NULL;
-    struct addrinfo hints, *info;
+    struct addrinfo hints = { 0 };
+    struct addrinfo *info;
 
     r = gethostname(hostname, sizeof(hostname));
     if (r == -1) {
@@ -453,7 +454,6 @@ virGetHostnameImpl(bool quiet)
      * canonicalize the hostname by running it through getaddrinfo
      */
 
-    memset(&hints, 0, sizeof(hints));
     hints.ai_flags = AI_CANONNAME|AI_CANONIDN;
     hints.ai_family = AF_UNSPEC;
     r = getaddrinfo(hostname, NULL, &hints, &info);
index fe4f253e9e26bcbaf39c43a9fc83e89161651dd5..5c6925be22377bbb6c57c08ef0a5da9af5104b37 100644 (file)
@@ -3229,7 +3229,7 @@ virVMXFormatConfig(virVMXContext *ctx, virDomainXMLOption *xmlopt, virDomainDef
     char *vmx = NULL;
     size_t i;
     int sched_cpu_affinity_length;
-    unsigned char zero[VIR_UUID_BUFLEN];
+    unsigned char zero[VIR_UUID_BUFLEN] = { 0 };
     g_auto(virBuffer) buffer = VIR_BUFFER_INITIALIZER;
     char *preliminaryDisplayName = NULL;
     char *displayName = NULL;
@@ -3247,8 +3247,6 @@ virVMXFormatConfig(virVMXContext *ctx, virDomainXMLOption *xmlopt, virDomainDef
         return NULL;
     }
 
-    memset(zero, 0, VIR_UUID_BUFLEN);
-
     if (def->virtType != VIR_DOMAIN_VIRT_VMWARE) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("Expecting virt type to be '%1$s' but found '%2$s'"),
index 205d34df1910a11bdd703f6bf5671ffa48b8c28e..f564a0ef729839d15b247edbce5753419ff89b3d 100644 (file)
@@ -60,9 +60,7 @@ VIR_MOCK_IMPL_RET_ARGS(libxl_get_version_info,
                        const libxl_version_info*,
                        libxl_ctx *, ctx)
 {
-    static libxl_version_info info;
-
-    memset(&info, 0, sizeof(info));
+    static libxl_version_info info = { 0 };
 
     /* silence gcc warning about unused function */
     if (0)
index a1740d3f45e2b1430959b167d9fa3485ffb134ba..2e7b661db49bf3a1c8f8471f79ba1619e07dae9f 100644 (file)
@@ -1591,15 +1591,14 @@ testQemuMonitorJSONqemuMonitorJSONGetMigrationStats(const void *opaque)
 {
     const testGenericData *data = opaque;
     virDomainXMLOption *xmlopt = data->xmlopt;
-    qemuMonitorMigrationStats stats, expectedStats;
+    qemuMonitorMigrationStats stats;
+    qemuMonitorMigrationStats expectedStats = { 0 };
     g_autofree char *error = NULL;
     g_autoptr(qemuMonitorTest) test = NULL;
 
     if (!(test = qemuMonitorTestNewSchema(xmlopt, data->schema)))
         return -1;
 
-    memset(&expectedStats, 0, sizeof(expectedStats));
-
     expectedStats.status = QEMU_MONITOR_MIGRATION_STATUS_ACTIVE;
     expectedStats.total_time = 47;
     expectedStats.ram_total = 1611038720;
index 6b9063e11d969014a428cd3de3f81b39c5a40dec..5cb8a9fb72ba3bdc8a3867f1e8e15f1ca385c895 100644 (file)
@@ -269,10 +269,9 @@ mymain(void)
 
 #define DO_TEST_PARSE_AND_FORMAT(addrstr, family, pass) \
     do { \
-        virSocketAddr addr; \
+        virSocketAddr addr = { 0 }; \
         struct testParseData data = { &addr, addrstr, family, pass }; \
         struct testFormatData data2 = { &addr, addrstr, pass }; \
-        memset(&addr, 0, sizeof(addr)); \
         if (virTestRun("Test parse " addrstr " family " #family, \
                        testParseHelper, &data) < 0) \
             ret = -1; \
@@ -283,10 +282,9 @@ mymain(void)
 
 #define DO_TEST_PARSE_AND_CHECK_FORMAT(addrstr, addrformated, family, pass) \
     do { \
-        virSocketAddr addr; \
+        virSocketAddr addr = { 0 }; \
         struct testParseData data = { &addr, addrstr, family, true}; \
         struct testFormatData data2 = { &addr, addrformated, pass }; \
-        memset(&addr, 0, sizeof(addr)); \
         if (virTestRun("Test parse " addrstr " family " #family, \
                        testParseHelper, &data) < 0) \
             ret = -1; \
index ec14ac804bacb202217e49efcbb8f1d55b90a147..b028f286081161afaa469e885463189176c3ec04 100644 (file)
@@ -538,15 +538,14 @@ _nss_compat_getaddrinfo(void *retval,
                         void *mdata __attribute__((unused)),
                         va_list ap)
 {
-    struct addrinfo sentinel, *cur, *ai;
+    struct addrinfo sentinel = { 0 };
+    struct addrinfo *cur = &sentinel;
+    struct addrinfo *ai;
     const char *name;
 
     name  = va_arg(ap, char *);
     ai = va_arg(ap, struct addrinfo *);
 
-    memset(&sentinel, 0, sizeof(sentinel));
-    cur = &sentinel;
-
     if ((ai->ai_family == AF_UNSPEC) || (ai->ai_family == AF_INET6))
         aiforaf(name, AF_INET6, ai, &cur);
     if ((ai->ai_family == AF_UNSPEC) || (ai->ai_family == AF_INET))
index 7d76055edad6d47533e5e27247da82b29ee0d812..f8758f18a3c9c4be92b813ca2a6a4e2eeed72d33 100644 (file)
@@ -942,7 +942,8 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd)
                *inboundStr = NULL, *outboundStr = NULL, *alias = NULL;
     const char *sourceModeStr = NULL;
     int sourceMode = -1;
-    virNetDevBandwidthRate inbound, outbound;
+    virNetDevBandwidthRate inbound = { 0 };
+    virNetDevBandwidthRate outbound = { 0 };
     virDomainNetType typ;
     int ret;
     g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
@@ -990,7 +991,6 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd)
     }
 
     if (inboundStr) {
-        memset(&inbound, 0, sizeof(inbound));
         if (virshParseRateStr(ctl, inboundStr, &inbound) < 0)
             return false;
         if (!inbound.average && !inbound.floor) {
@@ -999,7 +999,6 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd)
         }
     }
     if (outboundStr) {
-        memset(&outbound, 0, sizeof(outbound));
         if (virshParseRateStr(ctl, outboundStr, &outbound) < 0)
             return false;
         if (outbound.average == 0) {
@@ -3286,7 +3285,8 @@ cmdDomIftune(vshControl *ctl, const vshCmd *cmd)
     bool current = vshCommandOptBool(cmd, "current");
     bool config = vshCommandOptBool(cmd, "config");
     bool live = vshCommandOptBool(cmd, "live");
-    virNetDevBandwidthRate inbound, outbound;
+    virNetDevBandwidthRate inbound = { 0 };
+    virNetDevBandwidthRate outbound = { 0 };
     size_t i;
 
     VSH_EXCLUSIVE_OPTIONS_VAR(current, live);
@@ -3307,9 +3307,6 @@ cmdDomIftune(vshControl *ctl, const vshCmd *cmd)
         vshCommandOptStringReq(ctl, cmd, "outbound", &outboundStr) < 0)
         goto cleanup;
 
-    memset(&inbound, 0, sizeof(inbound));
-    memset(&outbound, 0, sizeof(outbound));
-
     if (inboundStr) {
         if (virshParseRateStr(ctl, inboundStr, &inbound) < 0)
             goto cleanup;