[PATCH 00/13] Use struct zero initializer instead of memset

This was inspired by Martin's comment here: https://listman.redhat.com/archives/libvir-list/2023-July/241007.html It has sent me down a rabbit hole. But hey, it helped me to identify some needless memset()-s, unused variables, problematic code patterns. Michal Prívozník (13): tools: Fix vshControl declaration and initialization virt-aa-helper: Use struct zero initializer instead of memset Decrease scope of some variables qemu: Don't reuse variable in processSerialChangedEvent() remote_driver: Drop explicit memset(&sargs) in remoteAuthSASL() virfirewalld: Drop useless memset() in virFirewallDApplyRule() virnetlink: Drop unused variable from virNetlinkCommand() securityselinuxhelper: Use g_new0() instead of malloc()+memset() combo virnetclient: Update comment about memset() virnetdaemon.c: Use struct zero initializer instead of memset lib: use struct zero initializer instead of memset lib: Finish using struct zero initializer manually lib: Prefer sizeof(variable) instead of sizeof(type) in memset src/ch/ch_monitor.c | 3 +- src/conf/domain_conf.c | 8 +- src/conf/network_conf.c | 28 ++---- src/cpu/cpu_x86.c | 4 +- src/esx/esx_driver.c | 20 ++--- src/esx/esx_interface_driver.c | 13 +-- src/esx/esx_storage_backend_iscsi.c | 11 +-- src/esx/esx_storage_backend_vmfs.c | 19 ++-- src/esx/esx_util.c | 4 +- src/libxl/libxl_capabilities.c | 4 +- src/libxl/libxl_driver.c | 9 +- src/locking/lock_driver_lockd.c | 19 ++-- src/logging/log_manager.c | 25 ++---- src/lxc/lxc_controller.c | 6 +- src/lxc/lxc_domain.c | 4 +- src/lxc/lxc_driver.c | 4 +- src/nwfilter/nwfilter_dhcpsnoop.c | 4 +- src/nwfilter/nwfilter_gentech_driver.c | 4 +- src/qemu/qemu_agent.c | 10 +-- src/qemu/qemu_command.c | 3 +- src/qemu/qemu_driver.c | 28 +++--- src/qemu/qemu_monitor.c | 10 +-- src/qemu/qemu_monitor_json.c | 11 +-- src/qemu/qemu_process.c | 5 +- src/remote/remote_daemon_dispatch.c | 115 ++++++++----------------- src/remote/remote_daemon_stream.c | 23 ++--- src/remote/remote_driver.c | 23 ++--- src/rpc/virnetclient.c | 4 +- src/rpc/virnetclientprogram.c | 4 +- src/rpc/virnetclientstream.c | 9 +- src/rpc/virnetdaemon.c | 10 +-- src/rpc/virnetsaslcontext.c | 3 +- src/rpc/virnetserverprogram.c | 14 +-- src/rpc/virnetsocket.c | 49 +++-------- src/rpc/virnetsshsession.c | 8 +- src/rpc/virnettlscontext.c | 3 +- src/security/virt-aa-helper.c | 5 +- src/storage/storage_backend_logical.c | 10 +-- src/storage/storage_driver.c | 2 +- src/test/test_driver.c | 4 +- src/util/virarptable.c | 3 +- src/util/virauth.c | 4 +- src/util/virbpf.c | 52 +++-------- src/util/virdevmapper.c | 8 +- src/util/virfdstream.c | 3 +- src/util/virfile.c | 3 +- src/util/virfirewalld.c | 2 - src/util/virinitctl.c | 4 +- src/util/viriscsi.c | 4 +- src/util/virlog.c | 9 +- src/util/virnetdev.c | 8 +- src/util/virnetdevbridge.c | 10 +-- src/util/virnetdevip.c | 8 +- src/util/virnetdevmacvlan.c | 3 +- src/util/virnetdevtap.c | 9 +- src/util/virnetlink.c | 7 +- src/util/virperf.c | 3 +- src/util/virprocess.c | 3 +- src/util/virsocket.c | 6 +- src/util/virsocketaddr.c | 7 +- src/util/viruri.c | 4 +- src/util/virutil.c | 4 +- src/util/viruuid.c | 4 +- src/vbox/vbox_storage.c | 10 +-- src/vmx/vmx.c | 8 +- tests/libxlmock.c | 4 +- tests/nsstest.c | 8 +- tests/nwfilterxml2firewalltest.c | 4 +- tests/qemumonitorjsontest.c | 11 +-- tests/qemumonitortestutils.c | 8 +- tests/qemuxml2argvtest.c | 4 +- tests/securityselinuxhelper.c | 5 +- tests/sockettest.c | 6 +- tests/virhostcputest.c | 3 +- tests/virnetmessagetest.c | 8 +- tests/virnetsockettest.c | 7 +- tools/nss/libvirt_nss.c | 10 +-- tools/virsh-domain-monitor.c | 10 +-- tools/virsh-domain.c | 15 ++-- tools/virsh.c | 7 +- tools/virt-admin.c | 7 +- tools/vsh-table.c | 4 +- 82 files changed, 258 insertions(+), 591 deletions(-) -- 2.41.0

Both virsh and virt-admin have vshControl typed variables and also pointers to these variables. In both cases these are declared on a single line. Do the following: 1) break declaration into two lines, 2) use struct zero initializer for vshControl and virshControl/vshAdmControl structs, 3) drop explicit memset(.., 0, ...) ; Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- tools/virsh.c | 7 +++---- tools/virt-admin.c | 7 +++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/tools/virsh.c b/tools/virsh.c index 963e886860..40c23e4180 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -831,12 +831,11 @@ static const vshClientHooks hooks = { int main(int argc, char **argv) { - vshControl _ctl, *ctl = &_ctl; - virshControl virshCtl; + vshControl _ctl = { 0 }; + vshControl *ctl = &_ctl; + virshControl virshCtl = { 0 }; bool ret = true; - memset(ctl, 0, sizeof(vshControl)); - memset(&virshCtl, 0, sizeof(virshControl)); ctl->name = "virsh"; /* hardcoded name of the binary */ ctl->env_prefix = "VIRSH"; ctl->log_fd = -1; /* Initialize log file descriptor */ diff --git a/tools/virt-admin.c b/tools/virt-admin.c index db246dc3a6..9d01890447 100644 --- a/tools/virt-admin.c +++ b/tools/virt-admin.c @@ -1554,12 +1554,11 @@ static const vshClientHooks hooks = { int main(int argc, char **argv) { - vshControl _ctl, *ctl = &_ctl; - vshAdmControl virtAdminCtl; + vshControl _ctl = { 0 }; + vshControl *ctl = &_ctl; + vshAdmControl virtAdminCtl = { 0 }; bool ret = true; - memset(ctl, 0, sizeof(vshControl)); - memset(&virtAdminCtl, 0, sizeof(vshAdmControl)); ctl->name = "virt-admin"; /* hardcoded name of the binary */ ctl->env_prefix = "VIRT_ADMIN"; ctl->log_fd = -1; /* Initialize log file descriptor */ -- 2.41.0

On 8/3/23 12:36, Michal Privoznik wrote:
Both virsh and virt-admin have vshControl typed variables and also pointers to these variables. In both cases these are declared on a single line. Do the following:
1) break declaration into two lines, 2) use struct zero initializer for vshControl and virshControl/vshAdmControl structs, 3) drop explicit memset(.., 0, ...) ;
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Claudio Fontana <cfontana@suse.de>
--- tools/virsh.c | 7 +++---- tools/virt-admin.c | 7 +++---- 2 files changed, 6 insertions(+), 8 deletions(-)
diff --git a/tools/virsh.c b/tools/virsh.c index 963e886860..40c23e4180 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -831,12 +831,11 @@ static const vshClientHooks hooks = { int main(int argc, char **argv) { - vshControl _ctl, *ctl = &_ctl; - virshControl virshCtl; + vshControl _ctl = { 0 }; + vshControl *ctl = &_ctl; + virshControl virshCtl = { 0 }; bool ret = true;
- memset(ctl, 0, sizeof(vshControl)); - memset(&virshCtl, 0, sizeof(virshControl)); ctl->name = "virsh"; /* hardcoded name of the binary */ ctl->env_prefix = "VIRSH"; ctl->log_fd = -1; /* Initialize log file descriptor */ diff --git a/tools/virt-admin.c b/tools/virt-admin.c index db246dc3a6..9d01890447 100644 --- a/tools/virt-admin.c +++ b/tools/virt-admin.c @@ -1554,12 +1554,11 @@ static const vshClientHooks hooks = { int main(int argc, char **argv) { - vshControl _ctl, *ctl = &_ctl; - vshAdmControl virtAdminCtl; + vshControl _ctl = { 0 }; + vshControl *ctl = &_ctl; + vshAdmControl virtAdminCtl = { 0 }; bool ret = true;
- memset(ctl, 0, sizeof(vshControl)); - memset(&virtAdminCtl, 0, sizeof(vshAdmControl)); ctl->name = "virt-admin"; /* hardcoded name of the binary */ ctl->env_prefix = "VIRT_ADMIN"; ctl->log_fd = -1; /* Initialize log file descriptor */

Thu, 3 Aug 2023 12:36:08 +0200 Michal Privoznik <mprivozn@redhat.com>:
+ vshControl _ctl = { 0 };
I see this often, instead of a simple 'type variable = {};', and wonder what that zero is doing here? Olaf

On 8/3/23 19:53, Olaf Hering wrote:
Thu, 3 Aug 2023 12:36:08 +0200 Michal Privoznik <mprivozn@redhat.com>:
+ vshControl _ctl = { 0 };
I see this often, instead of a simple 'type variable = {};', and wonder what that zero is doing here?
That's C23 standard: https://en.wikipedia.org/wiki/C23_(C_standard_revision)#Syntax Libvirt requires C99 with GNU extensions which don't have that AFAIK. OTOH, when turning on `-pedantic` compilation fails on the very first .c file. Anyway, it looks like we're using { 0 } everywhere else so that's why I went with it. But switching to {} should be as easy as: @@ @@ - { 0 } + {} (untested spatch) Or maybe even a bit of sed trickery can do it. Michal

Thu, 3 Aug 2023 21:38:02 +0200 Michal Prívozník <mprivozn@redhat.com>:
it looks like we're using { 0 } everywhere else so that's why I went with it.
I was under the impression {} is valid. But apparently it is not, so I learned something new today: "ISO C forbids empty initializer braces". Olaf

On 8/3/23 22:54, Olaf Hering wrote:
Thu, 3 Aug 2023 21:38:02 +0200 Michal Prívozník <mprivozn@redhat.com>:
it looks like we're using { 0 } everywhere else so that's why I went with it.
I was under the impression {} is valid. But apparently it is not, so I learned something new today: "ISO C forbids empty initializer braces".
Olaf
The next C, likely C23 or ISO/IEC 9899:2024 will include also {} as an alternative for { 0 }. I found this one interesting: https://www.youtube.com/watch?v=lLv1s7rKeCM Ciao, C

This is similar to the previous commit, except this is for a different type (vahControl) and also fixes the case where _ctl is passed not initialized to vah_error() (via ctl pointer so that's probably why compilers don't complain). Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/security/virt-aa-helper.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c index 3ee59b32bb..da1e4fc3e4 100644 --- a/src/security/virt-aa-helper.c +++ b/src/security/virt-aa-helper.c @@ -1433,7 +1433,8 @@ vahParseArgv(vahControl * ctl, int argc, char **argv) int main(int argc, char **argv) { - vahControl _ctl, *ctl = &_ctl; + vahControl _ctl = { 0 }; + vahControl *ctl = &_ctl; int rc = -1; char *profile = NULL; char *include_file = NULL; @@ -1466,8 +1467,6 @@ main(int argc, char **argv) else progname++; - memset(ctl, 0, sizeof(vahControl)); - if (vahParseArgv(ctl, argc, argv) != 0) vah_error(ctl, 1, _("could not parse arguments")); -- 2.41.0

On 8/3/23 12:36, Michal Privoznik wrote:
This is similar to the previous commit, except this is for a different type (vahControl) and also fixes the case where _ctl is passed not initialized to vah_error() (via ctl pointer so that's probably why compilers don't complain).
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Claudio Fontana <cfontana@suse.de>
--- src/security/virt-aa-helper.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c index 3ee59b32bb..da1e4fc3e4 100644 --- a/src/security/virt-aa-helper.c +++ b/src/security/virt-aa-helper.c @@ -1433,7 +1433,8 @@ vahParseArgv(vahControl * ctl, int argc, char **argv) int main(int argc, char **argv) { - vahControl _ctl, *ctl = &_ctl; + vahControl _ctl = { 0 }; + vahControl *ctl = &_ctl; int rc = -1; char *profile = NULL; char *include_file = NULL; @@ -1466,8 +1467,6 @@ main(int argc, char **argv) else progname++;
- memset(ctl, 0, sizeof(vahControl)); - if (vahParseArgv(ctl, argc, argv) != 0) vah_error(ctl, 1, _("could not parse arguments"));

There are couple of variables that are declared at function beginning but then used solely within a block (either for() loop or if() statement). And just before their use they are zeroed explicitly using memset(). Decrease their scope, use struct zero initializer and drop explicit memset(). Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/qemu/qemu_driver.c | 4 +--- src/remote/remote_driver.c | 7 +++---- src/rpc/virnetsshsession.c | 5 ++--- src/util/virnetdevmacvlan.c | 3 +-- src/util/virnetdevtap.c | 6 ++---- src/util/viruuid.c | 4 ++-- tests/virnetsockettest.c | 7 ++----- tools/virsh-domain-monitor.c | 7 ++----- 8 files changed, 15 insertions(+), 28 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 497923ffee..1d7b78d73b 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -17124,7 +17124,6 @@ qemuDomainGetStatsInterface(virQEMUDriver *driver G_GNUC_UNUSED, unsigned int privflags G_GNUC_UNUSED) { size_t i; - struct _virDomainInterfaceStats tmp; if (!virDomainObjIsActive(dom)) return 0; @@ -17135,12 +17134,11 @@ qemuDomainGetStatsInterface(virQEMUDriver *driver G_GNUC_UNUSED, for (i = 0; i < dom->def->nnets; i++) { virDomainNetDef *net = dom->def->nets[i]; virDomainNetType actualType; + struct _virDomainInterfaceStats tmp = { 0 }; if (!net->ifname) continue; - memset(&tmp, 0, sizeof(tmp)); - actualType = virDomainNetGetActualType(net); virTypedParamListAddString(params, net->ifname, "net.%zu.name", i); diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index 65ec239fb7..d775f65fe2 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -3728,8 +3728,6 @@ remoteAuthSASL(virConnectPtr conn, struct private_data *priv, remote_auth_sasl_init_ret iret; remote_auth_sasl_start_args sargs = {0}; remote_auth_sasl_start_ret sret; - remote_auth_sasl_step_args pargs = {0}; - remote_auth_sasl_step_ret pret; const char *clientout; char *serverin = NULL; size_t clientoutlen, serverinlen; @@ -3866,6 +3864,9 @@ remoteAuthSASL(virConnectPtr conn, struct private_data *priv, * Even if the server has completed, the client must *always* do at least one step * in this loop to verify the server isn't lying about something. Mutual auth */ for (;;) { + remote_auth_sasl_step_args pargs = { 0 }; + remote_auth_sasl_step_ret pret = { 0 }; + if ((err = virNetSASLSessionClientStep(sasl, serverin, serverinlen, @@ -3893,14 +3894,12 @@ remoteAuthSASL(virConnectPtr conn, struct private_data *priv, /* Not done, prepare to talk with the server for another iteration */ /* NB, distinction of NULL vs "" is *critical* in SASL */ - memset(&pargs, 0, sizeof(pargs)); pargs.nil = clientout ? 0 : 1; pargs.data.data_val = (char*)clientout; pargs.data.data_len = clientoutlen; VIR_DEBUG("Server step with %zu bytes %p", clientoutlen, clientout); - memset(&pret, 0, sizeof(pret)); if (call(conn, priv, 0, REMOTE_PROC_AUTH_SASL_STEP, (xdrproc_t) xdr_remote_auth_sasl_step_args, (char *) &pargs, (xdrproc_t) xdr_remote_auth_sasl_step_ret, (char *) &pret) != 0) diff --git a/src/rpc/virnetsshsession.c b/src/rpc/virnetsshsession.c index 1df43bb044..98be120a11 100644 --- a/src/rpc/virnetsshsession.c +++ b/src/rpc/virnetsshsession.c @@ -271,7 +271,6 @@ virNetSSHCheckHostKey(virNetSSHSession *sess) size_t keyLength; char *errmsg; g_auto(virBuffer) buff = VIR_BUFFER_INITIALIZER; - virConnectCredential askKey; struct libssh2_knownhost *knownHostEntry = NULL; size_t i; char *hostnameStr = NULL; @@ -303,6 +302,8 @@ virNetSSHCheckHostKey(virNetSSHSession *sess) case LIBSSH2_KNOWNHOST_CHECK_NOTFOUND: /* key was not found, query to add it to database */ if (sess->hostKeyVerify == VIR_NET_SSH_HOSTKEY_VERIFY_NORMAL) { + virConnectCredential askKey = { 0 }; + /* ask to add the key */ if (!sess->cred || !sess->cred->cb) { virReportError(VIR_ERR_SSH, "%s", @@ -312,8 +313,6 @@ virNetSSHCheckHostKey(virNetSSHSession *sess) } /* prepare data for the callback */ - memset(&askKey, 0, sizeof(virConnectCredential)); - for (i = 0; i < sess->cred->ncredtype; i++) { if (sess->cred->credtype[i] == VIR_CRED_ECHOPROMPT) break; diff --git a/src/util/virnetdevmacvlan.c b/src/util/virnetdevmacvlan.c index db5f41bae8..cde9d70eef 100644 --- a/src/util/virnetdevmacvlan.c +++ b/src/util/virnetdevmacvlan.c @@ -217,12 +217,11 @@ int virNetDevMacVLanTapSetup(int *tapfd, size_t tapfdSize, bool vnet_hdr) { unsigned int features; - struct ifreq ifreq; short new_flags = 0; size_t i; for (i = 0; i < tapfdSize; i++) { - memset(&ifreq, 0, sizeof(ifreq)); + struct ifreq ifreq = { 0 }; if (ioctl(tapfd[i], TUNGETIFF, &ifreq) < 0) { virReportSystemError(errno, "%s", diff --git a/src/util/virnetdevtap.c b/src/util/virnetdevtap.c index b85b753c96..3e25f18770 100644 --- a/src/util/virnetdevtap.c +++ b/src/util/virnetdevtap.c @@ -172,7 +172,6 @@ int virNetDevTapCreate(char **ifname, unsigned int flags) { size_t i = 0; - struct ifreq ifr; int rc; int ret = -1; int fd = -1; @@ -204,8 +203,9 @@ int virNetDevTapCreate(char **ifname, if (!tunpath) tunpath = "/dev/net/tun"; - memset(&ifr, 0, sizeof(ifr)); for (i = 0; i < tapfdSize; i++) { + struct ifreq ifr = { 0 }; + if ((fd = open(tunpath, O_RDWR)) < 0) { virReportSystemError(errno, _("Unable to open %1$s, is tun module loaded?"), @@ -213,8 +213,6 @@ int virNetDevTapCreate(char **ifname, goto cleanup; } - memset(&ifr, 0, sizeof(ifr)); - ifr.ifr_flags = IFF_TAP | IFF_NO_PI; /* If tapfdSize is greater than one, request multiqueue */ if (tapfdSize > 1) diff --git a/src/util/viruuid.c b/src/util/viruuid.c index ca22c91d48..a4f3a50fa5 100644 --- a/src/util/viruuid.c +++ b/src/util/viruuid.c @@ -215,13 +215,13 @@ int virSetHostUUIDStr(const char *uuid) { int rc; - char dmiuuid[VIR_UUID_STRING_BUFLEN]; if (virUUIDIsValid(host_uuid)) return EEXIST; if (!uuid) { - memset(dmiuuid, 0, sizeof(dmiuuid)); + char dmiuuid[VIR_UUID_STRING_BUFLEN] = { 0 }; + if (!getDMISystemUUID(dmiuuid, sizeof(dmiuuid))) { if (!virUUIDParse(dmiuuid, host_uuid)) return 0; diff --git a/tests/virnetsockettest.c b/tests/virnetsockettest.c index 2295e29777..0e9cd8a81c 100644 --- a/tests/virnetsockettest.c +++ b/tests/virnetsockettest.c @@ -44,8 +44,6 @@ static int checkProtocols(bool *hasIPv4, bool *hasIPv6, int *freePort) { - struct sockaddr_in in4; - struct sockaddr_in6 in6; size_t i; *freePort = 0; @@ -53,6 +51,8 @@ checkProtocols(bool *hasIPv4, bool *hasIPv6, return -1; for (i = 0; i < 50; i++) { + struct sockaddr_in in4 = { 0 }; + struct sockaddr_in6 in6 = { 0 }; VIR_AUTOCLOSE s4 = -1; VIR_AUTOCLOSE s6 = -1; @@ -71,9 +71,6 @@ checkProtocols(bool *hasIPv4, bool *hasIPv6, return -1; } - memset(&in4, 0, sizeof(in4)); - memset(&in6, 0, sizeof(in6)); - in4.sin_family = AF_INET; in4.sin_port = htons(BASE_PORT + i); in4.sin_addr.s_addr = htonl(INADDR_LOOPBACK); diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index ec99b9f99a..c74fc19347 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -444,7 +444,6 @@ cmdDomblkinfoGet(const virDomainBlockInfo *info, static bool cmdDomblkinfo(vshControl *ctl, const vshCmd *cmd) { - virDomainBlockInfo info; g_autoptr(virshDomain) dom = NULL; bool human = false; bool all = false; @@ -491,6 +490,7 @@ cmdDomblkinfo(vshControl *ctl, const vshCmd *cmd) g_autofree char *cap = NULL; g_autofree char *alloc = NULL; g_autofree char *phy = NULL; + virDomainBlockInfo info = { 0 }; ctxt->node = disks[i]; protocol = virXPathString("string(./source/@protocol)", ctxt); @@ -513,10 +513,6 @@ cmdDomblkinfo(vshControl *ctl, const vshCmd *cmd) return false; } } - } else { - /* if we don't call virDomainGetBlockInfo() who clears 'info' - * we have to do it manually */ - memset(&info, 0, sizeof(info)); } if (!cmdDomblkinfoGet(&info, &cap, &alloc, &phy, human)) @@ -531,6 +527,7 @@ cmdDomblkinfo(vshControl *ctl, const vshCmd *cmd) g_autofree char *cap = NULL; g_autofree char *alloc = NULL; g_autofree char *phy = NULL; + virDomainBlockInfo info = { 0 }; if (virDomainGetBlockInfo(dom, device, &info, 0) < 0) return false; -- 2.41.0

On 8/3/23 12:36, Michal Privoznik wrote:
There are couple of variables that are declared at function beginning but then used solely within a block (either for() loop or if() statement). And just before their use they are zeroed explicitly using memset(). Decrease their scope, use struct zero initializer and drop explicit memset().
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Claudio Fontana <cfontana@suse.de>
--- src/qemu/qemu_driver.c | 4 +--- src/remote/remote_driver.c | 7 +++---- src/rpc/virnetsshsession.c | 5 ++--- src/util/virnetdevmacvlan.c | 3 +-- src/util/virnetdevtap.c | 6 ++---- src/util/viruuid.c | 4 ++-- tests/virnetsockettest.c | 7 ++----- tools/virsh-domain-monitor.c | 7 ++----- 8 files changed, 15 insertions(+), 28 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 497923ffee..1d7b78d73b 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -17124,7 +17124,6 @@ qemuDomainGetStatsInterface(virQEMUDriver *driver G_GNUC_UNUSED, unsigned int privflags G_GNUC_UNUSED) { size_t i; - struct _virDomainInterfaceStats tmp;
if (!virDomainObjIsActive(dom)) return 0; @@ -17135,12 +17134,11 @@ qemuDomainGetStatsInterface(virQEMUDriver *driver G_GNUC_UNUSED, for (i = 0; i < dom->def->nnets; i++) { virDomainNetDef *net = dom->def->nets[i]; virDomainNetType actualType; + struct _virDomainInterfaceStats tmp = { 0 };
if (!net->ifname) continue;
- memset(&tmp, 0, sizeof(tmp)); - actualType = virDomainNetGetActualType(net);
virTypedParamListAddString(params, net->ifname, "net.%zu.name", i); diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index 65ec239fb7..d775f65fe2 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -3728,8 +3728,6 @@ remoteAuthSASL(virConnectPtr conn, struct private_data *priv, remote_auth_sasl_init_ret iret; remote_auth_sasl_start_args sargs = {0}; remote_auth_sasl_start_ret sret; - remote_auth_sasl_step_args pargs = {0}; - remote_auth_sasl_step_ret pret; const char *clientout; char *serverin = NULL; size_t clientoutlen, serverinlen; @@ -3866,6 +3864,9 @@ remoteAuthSASL(virConnectPtr conn, struct private_data *priv, * Even if the server has completed, the client must *always* do at least one step * in this loop to verify the server isn't lying about something. Mutual auth */ for (;;) { + remote_auth_sasl_step_args pargs = { 0 }; + remote_auth_sasl_step_ret pret = { 0 }; + if ((err = virNetSASLSessionClientStep(sasl, serverin, serverinlen, @@ -3893,14 +3894,12 @@ remoteAuthSASL(virConnectPtr conn, struct private_data *priv,
/* Not done, prepare to talk with the server for another iteration */ /* NB, distinction of NULL vs "" is *critical* in SASL */ - memset(&pargs, 0, sizeof(pargs)); pargs.nil = clientout ? 0 : 1; pargs.data.data_val = (char*)clientout; pargs.data.data_len = clientoutlen; VIR_DEBUG("Server step with %zu bytes %p", clientoutlen, clientout);
- memset(&pret, 0, sizeof(pret)); if (call(conn, priv, 0, REMOTE_PROC_AUTH_SASL_STEP, (xdrproc_t) xdr_remote_auth_sasl_step_args, (char *) &pargs, (xdrproc_t) xdr_remote_auth_sasl_step_ret, (char *) &pret) != 0) diff --git a/src/rpc/virnetsshsession.c b/src/rpc/virnetsshsession.c index 1df43bb044..98be120a11 100644 --- a/src/rpc/virnetsshsession.c +++ b/src/rpc/virnetsshsession.c @@ -271,7 +271,6 @@ virNetSSHCheckHostKey(virNetSSHSession *sess) size_t keyLength; char *errmsg; g_auto(virBuffer) buff = VIR_BUFFER_INITIALIZER; - virConnectCredential askKey; struct libssh2_knownhost *knownHostEntry = NULL; size_t i; char *hostnameStr = NULL; @@ -303,6 +302,8 @@ virNetSSHCheckHostKey(virNetSSHSession *sess) case LIBSSH2_KNOWNHOST_CHECK_NOTFOUND: /* key was not found, query to add it to database */ if (sess->hostKeyVerify == VIR_NET_SSH_HOSTKEY_VERIFY_NORMAL) { + virConnectCredential askKey = { 0 }; + /* ask to add the key */ if (!sess->cred || !sess->cred->cb) { virReportError(VIR_ERR_SSH, "%s", @@ -312,8 +313,6 @@ virNetSSHCheckHostKey(virNetSSHSession *sess) }
/* prepare data for the callback */ - memset(&askKey, 0, sizeof(virConnectCredential)); - for (i = 0; i < sess->cred->ncredtype; i++) { if (sess->cred->credtype[i] == VIR_CRED_ECHOPROMPT) break; diff --git a/src/util/virnetdevmacvlan.c b/src/util/virnetdevmacvlan.c index db5f41bae8..cde9d70eef 100644 --- a/src/util/virnetdevmacvlan.c +++ b/src/util/virnetdevmacvlan.c @@ -217,12 +217,11 @@ int virNetDevMacVLanTapSetup(int *tapfd, size_t tapfdSize, bool vnet_hdr) { unsigned int features; - struct ifreq ifreq; short new_flags = 0; size_t i;
for (i = 0; i < tapfdSize; i++) { - memset(&ifreq, 0, sizeof(ifreq)); + struct ifreq ifreq = { 0 };
if (ioctl(tapfd[i], TUNGETIFF, &ifreq) < 0) { virReportSystemError(errno, "%s", diff --git a/src/util/virnetdevtap.c b/src/util/virnetdevtap.c index b85b753c96..3e25f18770 100644 --- a/src/util/virnetdevtap.c +++ b/src/util/virnetdevtap.c @@ -172,7 +172,6 @@ int virNetDevTapCreate(char **ifname, unsigned int flags) { size_t i = 0; - struct ifreq ifr; int rc; int ret = -1; int fd = -1; @@ -204,8 +203,9 @@ int virNetDevTapCreate(char **ifname, if (!tunpath) tunpath = "/dev/net/tun";
- memset(&ifr, 0, sizeof(ifr)); for (i = 0; i < tapfdSize; i++) { + struct ifreq ifr = { 0 }; + if ((fd = open(tunpath, O_RDWR)) < 0) { virReportSystemError(errno, _("Unable to open %1$s, is tun module loaded?"), @@ -213,8 +213,6 @@ int virNetDevTapCreate(char **ifname, goto cleanup; }
- memset(&ifr, 0, sizeof(ifr)); - ifr.ifr_flags = IFF_TAP | IFF_NO_PI; /* If tapfdSize is greater than one, request multiqueue */ if (tapfdSize > 1) diff --git a/src/util/viruuid.c b/src/util/viruuid.c index ca22c91d48..a4f3a50fa5 100644 --- a/src/util/viruuid.c +++ b/src/util/viruuid.c @@ -215,13 +215,13 @@ int virSetHostUUIDStr(const char *uuid) { int rc; - char dmiuuid[VIR_UUID_STRING_BUFLEN];
if (virUUIDIsValid(host_uuid)) return EEXIST;
if (!uuid) { - memset(dmiuuid, 0, sizeof(dmiuuid)); + char dmiuuid[VIR_UUID_STRING_BUFLEN] = { 0 }; + if (!getDMISystemUUID(dmiuuid, sizeof(dmiuuid))) { if (!virUUIDParse(dmiuuid, host_uuid)) return 0; diff --git a/tests/virnetsockettest.c b/tests/virnetsockettest.c index 2295e29777..0e9cd8a81c 100644 --- a/tests/virnetsockettest.c +++ b/tests/virnetsockettest.c @@ -44,8 +44,6 @@ static int checkProtocols(bool *hasIPv4, bool *hasIPv6, int *freePort) { - struct sockaddr_in in4; - struct sockaddr_in6 in6; size_t i;
*freePort = 0; @@ -53,6 +51,8 @@ checkProtocols(bool *hasIPv4, bool *hasIPv6, return -1;
for (i = 0; i < 50; i++) { + struct sockaddr_in in4 = { 0 }; + struct sockaddr_in6 in6 = { 0 }; VIR_AUTOCLOSE s4 = -1; VIR_AUTOCLOSE s6 = -1;
@@ -71,9 +71,6 @@ checkProtocols(bool *hasIPv4, bool *hasIPv6, return -1; }
- memset(&in4, 0, sizeof(in4)); - memset(&in6, 0, sizeof(in6)); - in4.sin_family = AF_INET; in4.sin_port = htons(BASE_PORT + i); in4.sin_addr.s_addr = htonl(INADDR_LOOPBACK); diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index ec99b9f99a..c74fc19347 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -444,7 +444,6 @@ cmdDomblkinfoGet(const virDomainBlockInfo *info, static bool cmdDomblkinfo(vshControl *ctl, const vshCmd *cmd) { - virDomainBlockInfo info; g_autoptr(virshDomain) dom = NULL; bool human = false; bool all = false; @@ -491,6 +490,7 @@ cmdDomblkinfo(vshControl *ctl, const vshCmd *cmd) g_autofree char *cap = NULL; g_autofree char *alloc = NULL; g_autofree char *phy = NULL; + virDomainBlockInfo info = { 0 };
ctxt->node = disks[i]; protocol = virXPathString("string(./source/@protocol)", ctxt); @@ -513,10 +513,6 @@ cmdDomblkinfo(vshControl *ctl, const vshCmd *cmd) return false; } } - } else { - /* if we don't call virDomainGetBlockInfo() who clears 'info' - * we have to do it manually */ - memset(&info, 0, sizeof(info)); }
if (!cmdDomblkinfoGet(&info, &cap, &alloc, &phy, human)) @@ -531,6 +527,7 @@ cmdDomblkinfo(vshControl *ctl, const vshCmd *cmd) g_autofree char *cap = NULL; g_autofree char *alloc = NULL; g_autofree char *phy = NULL; + virDomainBlockInfo info = { 0 };
if (virDomainGetBlockInfo(dom, device, &info, 0) < 0) return false;

When a VSERPORT_CHANGE event is processed, we firstly do a little detour and try to detect whether the event is coming from guest agent. If so, we notify threads that are currently talking to the agent about this fact. Then we proceed with usual event processing (BeginJob(), update domain def, emit event, and so on). In both cases we use the same @dev variable to refer to domain device. While this works, it will make writing semantic patch unnecessary harder (see next commit(s)). Therefore, introduce a separate variable for the detour code. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/qemu/qemu_driver.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 1d7b78d73b..1f388306f4 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -3781,20 +3781,19 @@ processSerialChangedEvent(virQEMUDriver *driver, if (newstate == VIR_DOMAIN_CHR_DEVICE_STATE_DISCONNECTED && virDomainObjIsActive(vm) && priv->agent) { + virDomainDeviceDef agentDev; + /* peek into the domain definition to find the channel */ - if (virDomainDefFindDevice(vm->def, devAlias, &dev, true) == 0 && - dev.type == VIR_DOMAIN_DEVICE_CHR && - dev.data.chr->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_CHANNEL && - dev.data.chr->targetType == VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_VIRTIO && - STREQ_NULLABLE(dev.data.chr->target.name, "org.qemu.guest_agent.0")) + if (virDomainDefFindDevice(vm->def, devAlias, &agentDev, true) == 0 && + agentDev.type == VIR_DOMAIN_DEVICE_CHR && + agentDev.data.chr->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_CHANNEL && + agentDev.data.chr->targetType == VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_VIRTIO && + STREQ_NULLABLE(agentDev.data.chr->target.name, "org.qemu.guest_agent.0")) { /* Close agent monitor early, so that other threads * waiting for the agent to reply can finish and our * job we acquire below can succeed. */ qemuAgentNotifyClose(priv->agent); - - /* now discard the data, since it may possibly change once we unlock - * while entering the job */ - memset(&dev, 0, sizeof(dev)); + } } if (virDomainObjBeginJob(vm, VIR_JOB_MODIFY_MIGRATION_SAFE) < 0) -- 2.41.0

On 8/3/23 12:36, Michal Privoznik wrote:
When a VSERPORT_CHANGE event is processed, we firstly do a little detour and try to detect whether the event is coming from guest agent. If so, we notify threads that are currently talking to the agent about this fact. Then we proceed with usual event processing (BeginJob(), update domain def, emit event, and so on).
In both cases we use the same @dev variable to refer to domain device. While this works, it will make writing semantic patch unnecessary harder (see next commit(s)). Therefore, introduce a separate variable for the detour code.
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Claudio Fontana <cfontana@suse.de>
--- src/qemu/qemu_driver.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 1d7b78d73b..1f388306f4 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -3781,20 +3781,19 @@ processSerialChangedEvent(virQEMUDriver *driver,
if (newstate == VIR_DOMAIN_CHR_DEVICE_STATE_DISCONNECTED && virDomainObjIsActive(vm) && priv->agent) { + virDomainDeviceDef agentDev; + /* peek into the domain definition to find the channel */ - if (virDomainDefFindDevice(vm->def, devAlias, &dev, true) == 0 && - dev.type == VIR_DOMAIN_DEVICE_CHR && - dev.data.chr->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_CHANNEL && - dev.data.chr->targetType == VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_VIRTIO && - STREQ_NULLABLE(dev.data.chr->target.name, "org.qemu.guest_agent.0")) + if (virDomainDefFindDevice(vm->def, devAlias, &agentDev, true) == 0 && + agentDev.type == VIR_DOMAIN_DEVICE_CHR && + agentDev.data.chr->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_CHANNEL && + agentDev.data.chr->targetType == VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_VIRTIO && + STREQ_NULLABLE(agentDev.data.chr->target.name, "org.qemu.guest_agent.0")) { /* Close agent monitor early, so that other threads * waiting for the agent to reply can finish and our * job we acquire below can succeed. */ qemuAgentNotifyClose(priv->agent); - - /* now discard the data, since it may possibly change once we unlock - * while entering the job */ - memset(&dev, 0, sizeof(dev)); + } }
if (virDomainObjBeginJob(vm, VIR_JOB_MODIFY_MIGRATION_SAFE) < 0)

Inside of remoteAuthSASL() the sargs variable is already initialized to zero during declaration. There's no need to memset() it again as it's unused in between it's declaration and said memset(). Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/remote/remote_driver.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index d775f65fe2..7ccf550dff 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -3833,7 +3833,6 @@ remoteAuthSASL(virConnectPtr conn, struct private_data *priv, goto cleanup; } /* NB, distinction of NULL vs "" is *critical* in SASL */ - memset(&sargs, 0, sizeof(sargs)); sargs.nil = clientout ? 0 : 1; sargs.data.data_val = (char*)clientout; sargs.data.data_len = clientoutlen; -- 2.41.0

On 8/3/23 12:36, Michal Privoznik wrote:
Inside of remoteAuthSASL() the sargs variable is already initialized to zero during declaration. There's no need to memset() it again as it's unused in between it's declaration and said memset().
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Claudio Fontana <cfontana@suse.de>
--- src/remote/remote_driver.c | 1 - 1 file changed, 1 deletion(-)
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index d775f65fe2..7ccf550dff 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -3833,7 +3833,6 @@ remoteAuthSASL(virConnectPtr conn, struct private_data *priv, goto cleanup; } /* NB, distinction of NULL vs "" is *critical* in SASL */ - memset(&sargs, 0, sizeof(sargs)); sargs.nil = clientout ? 0 : 1; sargs.data.data_val = (char*)clientout; sargs.data.data_len = clientoutlen;

This is a residue of v6.8.0-rc1~100. The error variable inside of virFirewallDApplyRule() is already initialized to NULL. There's no need to memset() it to zero again. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/util/virfirewalld.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/util/virfirewalld.c b/src/util/virfirewalld.c index 6fc54f357d..827e201dbb 100644 --- a/src/util/virfirewalld.c +++ b/src/util/virfirewalld.c @@ -360,8 +360,6 @@ virFirewallDApplyRule(virFirewallLayer layer, if (!sysbus) return -1; - memset(&error, 0, sizeof(error)); - if (!ipv) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unknown firewall layer %1$d"), -- 2.41.0

On 8/3/23 12:36, Michal Privoznik wrote:
This is a residue of v6.8.0-rc1~100. The error variable inside of virFirewallDApplyRule() is already initialized to NULL. There's no need to memset() it to zero again.
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Claudio Fontana <cfontana@suse.de>
--- src/util/virfirewalld.c | 2 -- 1 file changed, 2 deletions(-)
diff --git a/src/util/virfirewalld.c b/src/util/virfirewalld.c index 6fc54f357d..827e201dbb 100644 --- a/src/util/virfirewalld.c +++ b/src/util/virfirewalld.c @@ -360,8 +360,6 @@ virFirewallDApplyRule(virFirewallLayer layer, if (!sysbus) return -1;
- memset(&error, 0, sizeof(error)); -
It was a quite convoluted way to just set a pointer to NULL ...
if (!ipv) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unknown firewall layer %1$d"),

The fds variable inside of virNetlinkCommand() is not used really. It's passed to memset() (hence compilers do not complain), but that's about it. Drop it. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/util/virnetlink.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/util/virnetlink.c b/src/util/virnetlink.c index 866f4d8f2b..d964c439b4 100644 --- a/src/util/virnetlink.c +++ b/src/util/virnetlink.c @@ -333,13 +333,10 @@ int virNetlinkCommand(struct nl_msg *nl_msg, .nl_pid = dst_pid, .nl_groups = 0, }; - struct pollfd fds[1]; g_autofree struct nlmsghdr *temp_resp = NULL; g_autoptr(virNetlinkHandle) nlhandle = NULL; int len = 0; - memset(fds, 0, sizeof(fds)); - if (!(nlhandle = virNetlinkSendRequest(nl_msg, src_pid, nladdr, protocol, groups))) return -1; -- 2.41.0

On 8/3/23 12:36, Michal Privoznik wrote:
The fds variable inside of virNetlinkCommand() is not used really. It's passed to memset() (hence compilers do not complain), but that's about it. Drop it.
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Claudio Fontana <cfontana@suse.de>
--- src/util/virnetlink.c | 3 --- 1 file changed, 3 deletions(-)
diff --git a/src/util/virnetlink.c b/src/util/virnetlink.c index 866f4d8f2b..d964c439b4 100644 --- a/src/util/virnetlink.c +++ b/src/util/virnetlink.c @@ -333,13 +333,10 @@ int virNetlinkCommand(struct nl_msg *nl_msg, .nl_pid = dst_pid, .nl_groups = 0, }; - struct pollfd fds[1]; g_autofree struct nlmsghdr *temp_resp = NULL; g_autoptr(virNetlinkHandle) nlhandle = NULL; int len = 0;
- memset(fds, 0, sizeof(fds)); - if (!(nlhandle = virNetlinkSendRequest(nl_msg, src_pid, nladdr, protocol, groups))) return -1;

Inside of securityselinuxhelper we still use malloc() + memset(.., 0, ...) combo. Convert it to g_new0(). Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- tests/securityselinuxhelper.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/securityselinuxhelper.c b/tests/securityselinuxhelper.c index c32c90c17e..797f090a7e 100644 --- a/tests/securityselinuxhelper.c +++ b/tests/securityselinuxhelper.c @@ -173,9 +173,8 @@ int getfilecon_raw(const char *path, char **con) } if (len < 0) return -1; - if (!(constr = malloc(len+1))) - return -1; - memset(constr, 0, len); + + constr = g_new0(char, len + 1); if (getxattr(path, "user.libvirt.selinux", constr, len) < 0) { free(constr); return -1; -- 2.41.0

On 8/3/23 12:36, Michal Privoznik wrote:
Inside of securityselinuxhelper we still use malloc() + memset(.., 0, ...) combo. Convert it to g_new0().
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
I don't think it is a good idea to mix Glib g_new, g_free etc with malloc, calloc, free. If you go with g_new0 here, imo you need to also change the calls to free() to g_free. The alternative is to use calloc instead, then you could leave the existing free calls alone. Ciao, Claudio
--- tests/securityselinuxhelper.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/tests/securityselinuxhelper.c b/tests/securityselinuxhelper.c index c32c90c17e..797f090a7e 100644 --- a/tests/securityselinuxhelper.c +++ b/tests/securityselinuxhelper.c @@ -173,9 +173,8 @@ int getfilecon_raw(const char *path, char **con) } if (len < 0) return -1; - if (!(constr = malloc(len+1))) - return -1; - memset(constr, 0, len); + + constr = g_new0(char, len + 1); if (getxattr(path, "user.libvirt.selinux", constr, len) < 0) { free(constr); return -1;

On 8/3/23 13:29, Claudio Fontana wrote:
On 8/3/23 12:36, Michal Privoznik wrote:
Inside of securityselinuxhelper we still use malloc() + memset(.., 0, ...) combo. Convert it to g_new0().
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
I don't think it is a good idea to mix Glib g_new, g_free etc with malloc, calloc, free.
If you go with g_new0 here, imo you need to also change the calls to free() to g_free.
The alternative is to use calloc instead, then you could leave the existing free calls alone.
Ah, good catch! Let me drop this from the series and post a switch to calloc() then. Thanks! Michal

Instead of suggesting to zero structs out using memset() we should suggest initializing structs with zero initializer. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/rpc/virnetclient.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rpc/virnetclient.c b/src/rpc/virnetclient.c index df2958935b..18f87653f5 100644 --- a/src/rpc/virnetclient.c +++ b/src/rpc/virnetclient.c @@ -1857,8 +1857,8 @@ static void virNetClientIOUpdateCallback(virNetClient *client, * which come from the user). It does however free any intermediate * results, eg. the error structure if there is one. * - * NB(2). Make sure to memset (&ret, 0, sizeof(ret)) before calling, - * else Bad Things will happen in the XDR code. + * NB(2). Make sure to initialize ret variable to { 0 } before calling, + * else Bad things will happen in the XDR code. * * NB(3) You must have the client lock before calling this * -- 2.41.0

On 8/3/23 12:36, Michal Privoznik wrote:
Instead of suggesting to zero structs out using memset() we should suggest initializing structs with zero initializer.
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Claudio Fontana <cfontana@suse.de>
--- src/rpc/virnetclient.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/rpc/virnetclient.c b/src/rpc/virnetclient.c index df2958935b..18f87653f5 100644 --- a/src/rpc/virnetclient.c +++ b/src/rpc/virnetclient.c @@ -1857,8 +1857,8 @@ static void virNetClientIOUpdateCallback(virNetClient *client, * which come from the user). It does however free any intermediate * results, eg. the error structure if there is one. * - * NB(2). Make sure to memset (&ret, 0, sizeof(ret)) before calling, - * else Bad Things will happen in the XDR code. + * NB(2). Make sure to initialize ret variable to { 0 } before calling, + * else Bad things will happen in the XDR code. * * NB(3) You must have the client lock before calling this *

Ideally, these would be fixed by coccinelle (see next commit), but because of various reasons they aren't. Fix them manually. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/rpc/virnetdaemon.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/rpc/virnetdaemon.c b/src/rpc/virnetdaemon.c index 554b8852e4..d37984d207 100644 --- a/src/rpc/virnetdaemon.c +++ b/src/rpc/virnetdaemon.c @@ -134,7 +134,7 @@ virNetDaemonNew(void) { virNetDaemon *dmn; #ifndef WIN32 - struct sigaction sig_action; + struct sigaction sig_action = { 0 }; #endif /* !WIN32 */ if (virNetDaemonInitialize() < 0) @@ -160,7 +160,6 @@ virNetDaemonNew(void) dmn->autoShutdownTimerID = -1; #ifndef WIN32 - memset(&sig_action, 0, sizeof(sig_action)); sig_action.sa_handler = SIG_IGN; sigaction(SIGPIPE, &sig_action, NULL); #endif /* !WIN32 */ @@ -599,12 +598,10 @@ virNetDaemonSignalHandler(int sig, siginfo_t * siginfo, { int origerrno; int r; - siginfo_t tmp; + siginfo_t tmp = { 0 }; if (SA_SIGINFO) tmp = *siginfo; - else - memset(&tmp, 0, sizeof(tmp)); /* set the sig num in the struct */ tmp.si_signo = sig; -- 2.41.0

On 8/3/23 12:36, Michal Privoznik wrote:
Ideally, these would be fixed by coccinelle (see next commit), but because of various reasons they aren't. Fix them manually.
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Claudio Fontana <cfontana@suse.de>
--- src/rpc/virnetdaemon.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/src/rpc/virnetdaemon.c b/src/rpc/virnetdaemon.c index 554b8852e4..d37984d207 100644 --- a/src/rpc/virnetdaemon.c +++ b/src/rpc/virnetdaemon.c @@ -134,7 +134,7 @@ virNetDaemonNew(void) { virNetDaemon *dmn; #ifndef WIN32 - struct sigaction sig_action; + struct sigaction sig_action = { 0 }; #endif /* !WIN32 */
if (virNetDaemonInitialize() < 0) @@ -160,7 +160,6 @@ virNetDaemonNew(void) dmn->autoShutdownTimerID = -1;
#ifndef WIN32 - memset(&sig_action, 0, sizeof(sig_action)); sig_action.sa_handler = SIG_IGN; sigaction(SIGPIPE, &sig_action, NULL); #endif /* !WIN32 */ @@ -599,12 +598,10 @@ virNetDaemonSignalHandler(int sig, siginfo_t * siginfo, { int origerrno; int r; - siginfo_t tmp; + siginfo_t tmp = { 0 };
if (SA_SIGINFO) tmp = *siginfo; - else - memset(&tmp, 0, sizeof(tmp));
/* set the sig num in the struct */ tmp.si_signo = sig;

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> --- src/ch/ch_monitor.c | 3 +- src/conf/domain_conf.c | 8 +- src/conf/network_conf.c | 28 ++---- src/cpu/cpu_x86.c | 4 +- src/esx/esx_driver.c | 20 ++--- src/esx/esx_interface_driver.c | 13 +-- src/esx/esx_storage_backend_iscsi.c | 11 +-- src/esx/esx_storage_backend_vmfs.c | 19 ++-- src/esx/esx_util.c | 4 +- src/libxl/libxl_driver.c | 9 +- src/locking/lock_driver_lockd.c | 19 ++-- src/logging/log_manager.c | 25 ++---- src/lxc/lxc_controller.c | 6 +- src/lxc/lxc_domain.c | 4 +- src/lxc/lxc_driver.c | 4 +- src/nwfilter/nwfilter_dhcpsnoop.c | 4 +- src/nwfilter/nwfilter_gentech_driver.c | 4 +- src/qemu/qemu_agent.c | 10 +-- src/qemu/qemu_command.c | 3 +- src/qemu/qemu_driver.c | 7 +- src/qemu/qemu_monitor.c | 6 +- src/qemu/qemu_monitor_json.c | 7 +- src/qemu/qemu_process.c | 3 +- src/remote/remote_daemon_dispatch.c | 115 ++++++++----------------- src/remote/remote_daemon_stream.c | 23 ++--- src/remote/remote_driver.c | 13 +-- src/rpc/virnetclientprogram.c | 4 +- src/rpc/virnetclientstream.c | 9 +- src/rpc/virnetdaemon.c | 3 +- src/rpc/virnetsaslcontext.c | 3 +- src/rpc/virnetserverprogram.c | 14 +-- src/rpc/virnetsocket.c | 49 +++-------- src/rpc/virnetsshsession.c | 3 +- src/storage/storage_backend_logical.c | 10 +-- src/util/virarptable.c | 3 +- src/util/virauth.c | 4 +- src/util/virbpf.c | 52 +++-------- src/util/virdevmapper.c | 8 +- src/util/virfdstream.c | 3 +- src/util/virfile.c | 3 +- src/util/virinitctl.c | 4 +- src/util/viriscsi.c | 4 +- src/util/virlog.c | 9 +- src/util/virnetdev.c | 8 +- src/util/virnetdevbridge.c | 10 +-- src/util/virnetdevip.c | 8 +- src/util/virnetdevtap.c | 3 +- src/util/virperf.c | 3 +- src/util/virprocess.c | 3 +- src/util/virsocket.c | 6 +- src/util/virsocketaddr.c | 7 +- src/util/viruri.c | 4 +- src/vbox/vbox_storage.c | 10 +-- src/vmx/vmx.c | 4 +- tests/nsstest.c | 8 +- tests/nwfilterxml2firewalltest.c | 4 +- tests/qemumonitorjsontest.c | 6 +- tests/qemumonitortestutils.c | 8 +- tests/qemuxml2argvtest.c | 4 +- tests/virhostcputest.c | 3 +- tests/virnetmessagetest.c | 8 +- tools/nss/libvirt_nss.c | 3 +- tools/virsh-domain-monitor.c | 3 +- tools/virsh-domain.c | 4 +- tools/vsh-table.c | 4 +- 65 files changed, 195 insertions(+), 483 deletions(-) diff --git a/src/ch/ch_monitor.c b/src/ch/ch_monitor.c index d902bc6959..a4b921931b 100644 --- a/src/ch/ch_monitor.c +++ b/src/ch/ch_monitor.c @@ -468,7 +468,7 @@ virCHMonitorBuildVMJson(virDomainDef *vmdef, static int chMonitorCreateSocket(const char *socket_path) { - struct sockaddr_un addr; + struct sockaddr_un addr = { 0 }; socklen_t addrlen = sizeof(addr); int fd; @@ -478,7 +478,6 @@ chMonitorCreateSocket(const char *socket_path) goto error; } - memset(&addr, 0, sizeof(addr)); addr.sun_family = AF_UNIX; if (virStrcpyStatic(addr.sun_path, socket_path) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 5ac5c0b771..47693a49bf 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -28859,9 +28859,7 @@ int virDomainGraphicsListenAppendAddress(virDomainGraphicsDef *def, const char *address) { - virDomainGraphicsListenDef glisten; - - memset(&glisten, 0, sizeof(glisten)); + virDomainGraphicsListenDef glisten = { 0 }; glisten.type = VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS; @@ -28877,9 +28875,7 @@ int virDomainGraphicsListenAppendSocket(virDomainGraphicsDef *def, const char *socketPath) { - virDomainGraphicsListenDef glisten; - - memset(&glisten, 0, sizeof(glisten)); + virDomainGraphicsListenDef glisten = { 0 }; glisten.type = VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_SOCKET; diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index 73788b6d87..3e137cb562 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -2748,11 +2748,9 @@ virNetworkDefUpdateIPDHCPHost(virNetworkDef *def, size_t i; int ret = -1; virNetworkIPDef *ipdef = virNetworkIPDefByIndex(def, parentIndex); - virNetworkDHCPHostDef host; + virNetworkDHCPHostDef host = { 0 }; bool partialOkay = (command == VIR_NETWORK_UPDATE_COMMAND_DELETE); - memset(&host, 0, sizeof(host)); - if (virNetworkDefUpdateCheckElementName(def, ctxt->node, "host") < 0) goto cleanup; @@ -2881,9 +2879,7 @@ virNetworkDefUpdateIPDHCPRange(virNetworkDef *def, { size_t i; virNetworkIPDef *ipdef = virNetworkIPDefByIndex(def, parentIndex); - virNetworkDHCPRangeDef range; - - memset(&range, 0, sizeof(range)); + virNetworkDHCPRangeDef range = { 0 }; if (virNetworkDefUpdateCheckElementName(def, ctxt->node, "range") < 0) return -1; @@ -2990,9 +2986,7 @@ virNetworkDefUpdateForwardInterface(virNetworkDef *def, { size_t i; int ret = -1; - virNetworkForwardIfDef iface; - - memset(&iface, 0, sizeof(iface)); + virNetworkForwardIfDef iface = { 0 }; if (virNetworkDefUpdateCheckElementName(def, ctxt->node, "interface") < 0) goto cleanup; @@ -3094,9 +3088,7 @@ virNetworkDefUpdatePortGroup(virNetworkDef *def, size_t i; int foundName = -1, foundDefault = -1; int ret = -1; - virPortGroupDef portgroup; - - memset(&portgroup, 0, sizeof(portgroup)); + virPortGroupDef portgroup = { 0 }; if (virNetworkDefUpdateCheckElementName(def, ctxt->node, "portgroup") < 0) goto cleanup; @@ -3184,13 +3176,11 @@ virNetworkDefUpdateDNSHost(virNetworkDef *def, size_t i, j, k; int foundIdx = -1, ret = -1; virNetworkDNSDef *dns = &def->dns; - virNetworkDNSHostDef host; + virNetworkDNSHostDef host = { 0 }; bool isAdd = (command == VIR_NETWORK_UPDATE_COMMAND_ADD_FIRST || command == VIR_NETWORK_UPDATE_COMMAND_ADD_LAST); int foundCt = 0; - memset(&host, 0, sizeof(host)); - if (command == VIR_NETWORK_UPDATE_COMMAND_MODIFY) { virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", _("DNS HOST records cannot be modified, " @@ -3283,13 +3273,11 @@ virNetworkDefUpdateDNSSrv(virNetworkDef *def, size_t i; int foundIdx = -1, ret = -1; virNetworkDNSDef *dns = &def->dns; - virNetworkDNSSrvDef srv; + virNetworkDNSSrvDef srv = { 0 }; bool isAdd = (command == VIR_NETWORK_UPDATE_COMMAND_ADD_FIRST || command == VIR_NETWORK_UPDATE_COMMAND_ADD_LAST); int foundCt = 0; - memset(&srv, 0, sizeof(srv)); - if (command == VIR_NETWORK_UPDATE_COMMAND_MODIFY) { virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", _("DNS SRV records cannot be modified, " @@ -3368,12 +3356,10 @@ virNetworkDefUpdateDNSTxt(virNetworkDef *def, { int foundIdx, ret = -1; virNetworkDNSDef *dns = &def->dns; - virNetworkDNSTxtDef txt; + virNetworkDNSTxtDef txt = { 0 }; bool isAdd = (command == VIR_NETWORK_UPDATE_COMMAND_ADD_FIRST || command == VIR_NETWORK_UPDATE_COMMAND_ADD_LAST); - memset(&txt, 0, sizeof(txt)); - if (command == VIR_NETWORK_UPDATE_COMMAND_MODIFY) { virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", _("DNS TXT records cannot be modified, " diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c index 3c0163c4d1..b9513e24d5 100644 --- a/src/cpu/cpu_x86.c +++ b/src/cpu/cpu_x86.c @@ -1073,9 +1073,7 @@ static int x86ParseMSR(xmlNodePtr node, virCPUx86DataItem *item) { - virCPUx86MSR msr; - - memset(&msr, 0, sizeof(msr)); + virCPUx86MSR msr = { 0 }; if (virXMLPropUInt(node, "index", 0, VIR_XML_PROP_REQUIRED, &msr.index) < 0) return -1; diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c index 0d1b10fe8b..b243bbf411 100644 --- a/src/esx/esx_driver.c +++ b/src/esx/esx_driver.c @@ -2536,14 +2536,12 @@ esxDomainGetXMLDesc(virDomainPtr domain, unsigned int flags) g_autofree char *url = NULL; g_autofree char *vmx = NULL; virVMXContext ctx; - esxVMX_Data data; + esxVMX_Data data = { 0 }; g_autoptr(virDomainDef) def = NULL; char *xml = NULL; virCheckFlags(VIR_DOMAIN_XML_COMMON_FLAGS, NULL); - memset(&data, 0, sizeof(data)); - if (esxVI_EnsureSession(priv->primary) < 0) return NULL; @@ -2622,14 +2620,12 @@ esxConnectDomainXMLFromNative(virConnectPtr conn, const char *nativeFormat, { esxPrivate *priv = conn->privateData; virVMXContext ctx; - esxVMX_Data data; + esxVMX_Data data = { 0 }; g_autoptr(virDomainDef) def = NULL; char *xml = NULL; virCheckFlags(0, NULL); - memset(&data, 0, sizeof(data)); - if (STRNEQ(nativeFormat, VMX_CONFIG_FORMAT_ARGV)) { virReportError(VIR_ERR_INVALID_ARG, _("Unsupported config format '%1$s'"), nativeFormat); @@ -2665,14 +2661,12 @@ esxConnectDomainXMLToNative(virConnectPtr conn, const char *nativeFormat, esxPrivate *priv = conn->privateData; int virtualHW_version; virVMXContext ctx; - esxVMX_Data data; + esxVMX_Data data = { 0 }; g_autoptr(virDomainDef) def = NULL; char *vmx = NULL; virCheckFlags(0, NULL); - memset(&data, 0, sizeof(data)); - if (STRNEQ(nativeFormat, VMX_CONFIG_FORMAT_ARGV)) { virReportError(VIR_ERR_INVALID_ARG, _("Unsupported config format '%1$s'"), nativeFormat); @@ -2870,7 +2864,7 @@ esxDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags) esxVI_ObjectContent *virtualMachine = NULL; int virtualHW_version; virVMXContext ctx; - esxVMX_Data data; + esxVMX_Data data = { 0 }; g_autofree char *datastoreName = NULL; g_autofree char *directoryName = NULL; g_autofree char *escapedName = NULL; @@ -2892,8 +2886,6 @@ esxDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags) if (flags & VIR_DOMAIN_DEFINE_VALIDATE) parse_flags |= VIR_DOMAIN_DEF_PARSE_VALIDATE_SCHEMA; - memset(&data, 0, sizeof(data)); - if (esxVI_EnsureSession(priv->primary) < 0) return NULL; @@ -4058,14 +4050,12 @@ esxDomainSnapshotGetXMLDesc(virDomainSnapshotPtr snapshot, esxVI_VirtualMachineSnapshotTree *rootSnapshotList = NULL; esxVI_VirtualMachineSnapshotTree *snapshotTree = NULL; esxVI_VirtualMachineSnapshotTree *snapshotTreeParent = NULL; - virDomainSnapshotDef def; + virDomainSnapshotDef def = { 0 }; char uuid_string[VIR_UUID_STRING_BUFLEN] = ""; char *xml = NULL; virCheckFlags(0, NULL); - memset(&def, 0, sizeof(def)); - if (esxVI_EnsureSession(priv->primary) < 0) return NULL; diff --git a/src/esx/esx_interface_driver.c b/src/esx/esx_interface_driver.c index d6b6410d1a..125155da99 100644 --- a/src/esx/esx_interface_driver.c +++ b/src/esx/esx_interface_driver.c @@ -157,21 +157,16 @@ esxInterfaceGetXMLDesc(virInterfacePtr iface, unsigned int flags) char *xml = NULL; esxPrivate *priv = iface->conn->privateData; esxVI_PhysicalNic *physicalNic = NULL; - virInterfaceDef def; + virInterfaceDef def = { 0 }; bool hasAddress = false; virInterfaceProtocolDef *protocols; - virInterfaceProtocolDef protocol; - virSocketAddr socketAddress; + virInterfaceProtocolDef protocol = { 0 }; + virSocketAddr socketAddress = { 0 }; virInterfaceIPDef *ips; - virInterfaceIPDef ip; + virInterfaceIPDef ip = { 0 }; virCheckFlags(VIR_INTERFACE_XML_INACTIVE, NULL); - memset(&def, 0, sizeof(def)); - memset(&protocol, 0, sizeof(protocol)); - memset(&socketAddress, 0, sizeof(socketAddress)); - memset(&ip, 0, sizeof(ip)); - if (esxVI_EnsureSession(priv->primary) < 0 || esxVI_LookupPhysicalNicByMACAddress(priv->primary, iface->mac, &physicalNic, diff --git a/src/esx/esx_storage_backend_iscsi.c b/src/esx/esx_storage_backend_iscsi.c index 087365392b..c00b1e4f32 100644 --- a/src/esx/esx_storage_backend_iscsi.c +++ b/src/esx/esx_storage_backend_iscsi.c @@ -302,12 +302,10 @@ esxStoragePoolGetXMLDesc(virStoragePoolPtr pool, unsigned int flags) esxPrivate *priv = pool->conn->privateData; esxVI_HostInternetScsiHba *hostInternetScsiHba = NULL; esxVI_HostInternetScsiHbaStaticTarget *target; - virStoragePoolDef def; + virStoragePoolDef def = { 0 }; virCheckFlags(0, NULL); - memset(&def, 0, sizeof(def)); - if (esxVI_LookupHostInternetScsiHba(priv->primary, &hostInternetScsiHba)) goto cleanup; @@ -664,20 +662,17 @@ esxStorageVolGetXMLDesc(virStorageVolPtr volume, { char *xml = NULL; esxPrivate *priv = volume->conn->privateData; - virStoragePoolDef pool; + virStoragePoolDef pool = { 0 }; esxVI_ScsiLun *scsiLunList = NULL; esxVI_ScsiLun *scsiLun; esxVI_HostScsiDisk *hostScsiDisk = NULL; - virStorageVolDef def; + virStorageVolDef def = { 0 }; /* VIR_CRYPTO_HASH_SIZE_MD5 = VIR_UUID_BUFLEN = 16 */ unsigned char md5[VIR_CRYPTO_HASH_SIZE_MD5]; char uuid_string[VIR_UUID_STRING_BUFLEN] = ""; virCheckFlags(0, NULL); - memset(&pool, 0, sizeof(pool)); - memset(&def, 0, sizeof(def)); - if (esxVI_LookupScsiLunList(priv->primary, &scsiLunList) < 0) goto cleanup; diff --git a/src/esx/esx_storage_backend_vmfs.c b/src/esx/esx_storage_backend_vmfs.c index f00c7eec4e..7c5df1c9cd 100644 --- a/src/esx/esx_storage_backend_vmfs.c +++ b/src/esx/esx_storage_backend_vmfs.c @@ -442,15 +442,13 @@ esxStoragePoolGetXMLDesc(virStoragePoolPtr pool, unsigned int flags) esxVI_DatastoreHostMount *hostMount = NULL; esxVI_DynamicProperty *dynamicProperty = NULL; esxVI_Boolean accessible = esxVI_Boolean_Undefined; - virStoragePoolDef def; + virStoragePoolDef def = { 0 }; esxVI_DatastoreInfo *info = NULL; esxVI_NasDatastoreInfo *nasInfo = NULL; char *xml = NULL; virCheckFlags(0, NULL); - memset(&def, 0, sizeof(def)); - if (esxVI_String_AppendValueListToList(&propertyNameList, "summary.accessible\0" "summary.capacity\0" @@ -833,7 +831,7 @@ esxStorageVolCreateXML(virStoragePoolPtr pool, { virStorageVolPtr volume = NULL; esxPrivate *priv = pool->conn->privateData; - virStoragePoolDef poolDef; + virStoragePoolDef poolDef = { 0 }; char *tmp; g_autofree char *unescapedDatastorePath = NULL; g_autofree char *unescapedDirectoryName = NULL; @@ -853,8 +851,6 @@ esxStorageVolCreateXML(virStoragePoolPtr pool, virCheckFlags(0, NULL); - memset(&poolDef, 0, sizeof(poolDef)); - if (esxLookupVMFSStoragePoolType(priv->primary, pool->name, &poolDef.type) < 0) { goto cleanup; @@ -1032,7 +1028,7 @@ esxStorageVolCreateXMLFrom(virStoragePoolPtr pool, { virStorageVolPtr volume = NULL; esxPrivate *priv = pool->conn->privateData; - virStoragePoolDef poolDef; + virStoragePoolDef poolDef = { 0 }; g_autofree char *sourceDatastorePath = NULL; char *tmp; g_autofree char *unescapedDatastorePath = NULL; @@ -1052,8 +1048,6 @@ esxStorageVolCreateXMLFrom(virStoragePoolPtr pool, virCheckFlags(0, NULL); - memset(&poolDef, 0, sizeof(poolDef)); - if (esxLookupVMFSStoragePoolType(priv->primary, pool->name, &poolDef.type) < 0) { goto cleanup; @@ -1312,20 +1306,17 @@ esxStorageVolGetXMLDesc(virStorageVolPtr volume, unsigned int flags) { esxPrivate *priv = volume->conn->privateData; - virStoragePoolDef pool; + virStoragePoolDef pool = { 0 }; g_autofree char *datastorePath = NULL; esxVI_FileInfo *fileInfo = NULL; esxVI_VmDiskFileInfo *vmDiskFileInfo = NULL; esxVI_IsoImageFileInfo *isoImageFileInfo = NULL; esxVI_FloppyImageFileInfo *floppyImageFileInfo = NULL; - virStorageVolDef def; + virStorageVolDef def = { 0 }; char *xml = NULL; virCheckFlags(0, NULL); - memset(&pool, 0, sizeof(pool)); - memset(&def, 0, sizeof(def)); - if (esxLookupVMFSStoragePoolType(priv->primary, volume->pool, &pool.type) < 0) { return NULL; diff --git a/src/esx/esx_util.c b/src/esx/esx_util.c index fbbf226555..785701a518 100644 --- a/src/esx/esx_util.c +++ b/src/esx/esx_util.c @@ -272,13 +272,11 @@ esxUtil_ParseDatastorePath(const char *datastorePath, char **datastoreName, int esxUtil_ResolveHostname(const char *hostname, char **ipAddress) { - struct addrinfo hints; + struct addrinfo hints = { 0 }; struct addrinfo *result = NULL; int errcode; g_autofree char *address = NULL; - memset(&hints, 0, sizeof(hints)); - hints.ai_flags = AI_ADDRCONFIG; hints.ai_family = AF_INET; hints.ai_socktype = SOCK_STREAM; diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index 2644d1400a..3d10f45850 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -1796,7 +1796,7 @@ libxlDoDomainSave(libxlDriverPrivate *driver, bool managed) { libxlDriverConfig *cfg = libxlDriverConfigGet(driver); - libxlSavefileHeader hdr; + libxlSavefileHeader hdr = { 0 }; virObjectEvent *event = NULL; g_autofree char *xml = NULL; uint32_t xml_len; @@ -1821,7 +1821,6 @@ libxlDoDomainSave(libxlDriverPrivate *driver, goto cleanup; xml_len = strlen(xml) + 1; - memset(&hdr, 0, sizeof(hdr)); memcpy(hdr.magic, LIBXL_SAVE_MAGIC, sizeof(hdr.magic)); hdr.version = LIBXL_SAVE_VERSION; hdr.xmlLen = xml_len; @@ -5651,7 +5650,7 @@ libxlDomainBlockStats(virDomainPtr dom, virDomainBlockStatsPtr stats) { virDomainObj *vm; - libxlBlockStats blkstats; + libxlBlockStats blkstats = { 0 }; int ret = -1; if (!(vm = libxlDomObjFromDomain(dom))) @@ -5666,7 +5665,6 @@ libxlDomainBlockStats(virDomainPtr dom, if (virDomainObjCheckActive(vm) < 0) goto endjob; - memset(&blkstats, 0, sizeof(libxlBlockStats)); if ((ret = libxlDomainBlockStatsGather(vm, path, &blkstats)) < 0) goto endjob; @@ -5695,7 +5693,7 @@ libxlDomainBlockStatsFlags(virDomainPtr dom, unsigned int flags) { virDomainObj *vm; - libxlBlockStats blkstats; + libxlBlockStats blkstats = { 0 }; int nstats; int ret = -1; @@ -5722,7 +5720,6 @@ libxlDomainBlockStatsFlags(virDomainPtr dom, goto endjob; } - memset(&blkstats, 0, sizeof(libxlBlockStats)); if ((ret = libxlDomainBlockStatsGather(vm, path, &blkstats)) < 0) goto endjob; diff --git a/src/locking/lock_driver_lockd.c b/src/locking/lock_driver_lockd.c index 6b294e2954..d75302dd0a 100644 --- a/src/locking/lock_driver_lockd.c +++ b/src/locking/lock_driver_lockd.c @@ -138,9 +138,7 @@ virLockManagerLockDaemonConnectionRegister(virLockManager *lock, int *counter) { virLockManagerLockDaemonPrivate *priv = lock->privateData; - virLockSpaceProtocolRegisterArgs args; - - memset(&args, 0, sizeof(args)); + virLockSpaceProtocolRegisterArgs args = { 0 }; args.flags = 0; memcpy(args.owner.uuid, priv->uuid, VIR_UUID_BUFLEN); @@ -167,9 +165,7 @@ virLockManagerLockDaemonConnectionRestrict(virLockManager *lock G_GNUC_UNUSED, virNetClientProgram *program, int *counter) { - virLockSpaceProtocolRestrictArgs args; - - memset(&args, 0, sizeof(args)); + virLockSpaceProtocolRestrictArgs args = { 0 }; args.flags = 0; @@ -259,11 +255,10 @@ static int virLockManagerLockDaemonSetupLockspace(const char *path) { virNetClient *client; virNetClientProgram *program = NULL; - virLockSpaceProtocolCreateLockSpaceArgs args; + virLockSpaceProtocolCreateLockSpaceArgs args = { 0 }; int rv = -1; int counter = 0; - memset(&args, 0, sizeof(args)); args.path = (char*)path; if (!(client = virLockManagerLockDaemonConnectionNew(geteuid() == 0, &program))) @@ -671,9 +666,7 @@ static int virLockManagerLockDaemonAcquire(virLockManager *lock, if (!(flags & VIR_LOCK_MANAGER_ACQUIRE_REGISTER_ONLY)) { size_t i; for (i = 0; i < priv->nresources; i++) { - virLockSpaceProtocolAcquireResourceArgs args; - - memset(&args, 0, sizeof(args)); + virLockSpaceProtocolAcquireResourceArgs args = { 0 }; args.path = priv->resources[i].lockspace; args.name = priv->resources[i].name; @@ -726,9 +719,7 @@ static int virLockManagerLockDaemonRelease(virLockManager *lock, goto cleanup; for (i = 0; i < priv->nresources; i++) { - virLockSpaceProtocolReleaseResourceArgs args; - - memset(&args, 0, sizeof(args)); + virLockSpaceProtocolReleaseResourceArgs args = { 0 }; if (priv->resources[i].lockspace) args.path = priv->resources[i].lockspace; diff --git a/src/logging/log_manager.c b/src/logging/log_manager.c index 6e8e7e9f1a..d8490f4e5a 100644 --- a/src/logging/log_manager.c +++ b/src/logging/log_manager.c @@ -149,15 +149,12 @@ virLogManagerDomainOpenLogFile(virLogManager *mgr, ino_t *inode, off_t *offset) { - struct virLogManagerProtocolDomainOpenLogFileArgs args; - struct virLogManagerProtocolDomainOpenLogFileRet ret; + struct virLogManagerProtocolDomainOpenLogFileArgs args = { 0 }; + struct virLogManagerProtocolDomainOpenLogFileRet ret = { 0 }; int *fdout = NULL; size_t fdoutlen = 0; int rv = -1; - memset(&args, 0, sizeof(args)); - memset(&ret, 0, sizeof(ret)); - args.driver = (char *)driver; memcpy(args.dom.uuid, domuuid, VIR_UUID_BUFLEN); args.dom.name = (char *)domname; @@ -208,11 +205,8 @@ virLogManagerDomainGetLogFilePosition(virLogManager *mgr, ino_t *inode, off_t *offset) { - struct virLogManagerProtocolDomainGetLogFilePositionArgs args; - struct virLogManagerProtocolDomainGetLogFilePositionRet ret; - - memset(&args, 0, sizeof(args)); - memset(&ret, 0, sizeof(ret)); + struct virLogManagerProtocolDomainGetLogFilePositionArgs args = { 0 }; + struct virLogManagerProtocolDomainGetLogFilePositionRet ret = { 0 }; args.path = (char *)path; args.flags = flags; @@ -241,11 +235,8 @@ virLogManagerDomainReadLogFile(virLogManager *mgr, size_t maxlen, unsigned int flags) { - struct virLogManagerProtocolDomainReadLogFileArgs args; - struct virLogManagerProtocolDomainReadLogFileRet ret; - - memset(&args, 0, sizeof(args)); - memset(&ret, 0, sizeof(ret)); + struct virLogManagerProtocolDomainReadLogFileArgs args = { 0 }; + struct virLogManagerProtocolDomainReadLogFileRet ret = { 0 }; args.path = (char *)path; args.flags = flags; @@ -275,11 +266,9 @@ virLogManagerDomainAppendMessage(virLogManager *mgr, const char *message, unsigned int flags) { - struct virLogManagerProtocolDomainAppendLogFileArgs args; + struct virLogManagerProtocolDomainAppendLogFileArgs args = { 0 }; struct virLogManagerProtocolDomainAppendLogFileRet ret; - memset(&args, 0, sizeof(args)); - args.driver = (char *)driver; memcpy(args.dom.uuid, domuuid, VIR_UUID_BUFLEN); args.dom.name = (char *)domname; diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c index 86dcd880e8..51459b47e7 100644 --- a/src/lxc/lxc_controller.c +++ b/src/lxc/lxc_controller.c @@ -2235,10 +2235,9 @@ static int virLXCControllerEventSendExit(virLXCController *ctrl, int exitstatus) { - virLXCMonitorExitEventMsg msg; + virLXCMonitorExitEventMsg msg = { 0 }; VIR_DEBUG("Exit status %d (client=%p)", exitstatus, ctrl->client); - memset(&msg, 0, sizeof(msg)); switch (exitstatus) { case 0: msg.status = VIR_LXC_MONITOR_EXIT_STATUS_SHUTDOWN; @@ -2272,10 +2271,9 @@ static int virLXCControllerEventSendInit(virLXCController *ctrl, pid_t initpid) { - virLXCMonitorInitEventMsg msg; + virLXCMonitorInitEventMsg msg = { 0 }; VIR_DEBUG("Init pid %lld", (long long)initpid); - memset(&msg, 0, sizeof(msg)); msg.initpid = initpid; virLXCControllerEventSend(ctrl, diff --git a/src/lxc/lxc_domain.c b/src/lxc/lxc_domain.c index e8c87423bf..cf9bf96a4e 100644 --- a/src/lxc/lxc_domain.c +++ b/src/lxc/lxc_domain.c @@ -339,13 +339,11 @@ virLXCDomainSetRunlevel(virDomainObj *vm, int runlevel) { virLXCDomainObjPrivate *priv = vm->privateData; - lxcDomainInitctlCallbackData data; + lxcDomainInitctlCallbackData data = { 0 }; size_t nfifos = 0; size_t i; int ret = -1; - memset(&data, 0, sizeof(data)); - data.runlevel = runlevel; for (nfifos = 0; virInitctlFifos[nfifos]; nfifos++) diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 3bc01cbc23..f284798f1c 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -3327,9 +3327,7 @@ lxcDomainAttachDeviceMknod(virLXCDriver *driver, char *file) { virLXCDomainObjPrivate *priv = vm->privateData; - struct lxcDomainAttachDeviceMknodData data; - - memset(&data, 0, sizeof(data)); + struct lxcDomainAttachDeviceMknodData data = { 0 }; data.driver = driver; data.mode = mode; diff --git a/src/nwfilter/nwfilter_dhcpsnoop.c b/src/nwfilter/nwfilter_dhcpsnoop.c index 3dc0b777e9..2f89923856 100644 --- a/src/nwfilter/nwfilter_dhcpsnoop.c +++ b/src/nwfilter/nwfilter_dhcpsnoop.c @@ -817,7 +817,7 @@ virNWFilterSnoopDHCPDecode(virNWFilterSnoopReq *req, struct iphdr *pip; struct udphdr *pup; virNWFilterSnoopDHCPHdr *pd; - virNWFilterSnoopIPLease ipl; + virNWFilterSnoopIPLease ipl = { 0 }; uint8_t mtype; uint32_t leasetime; uint32_t nwint; @@ -863,8 +863,6 @@ virNWFilterSnoopDHCPDecode(virNWFilterSnoopReq *req, if (virNWFilterSnoopDHCPGetOpt(pd, len, &mtype, &leasetime) < 0) return -2; - memset(&ipl, 0, sizeof(ipl)); - memcpy(&nwint, &pd->d_yiaddr, sizeof(nwint)); virSocketAddrSetIPv4AddrNetOrder(&ipl.ipAddress, nwint); diff --git a/src/nwfilter/nwfilter_gentech_driver.c b/src/nwfilter/nwfilter_gentech_driver.c index 72e24e2f08..41f270bb7c 100644 --- a/src/nwfilter/nwfilter_gentech_driver.c +++ b/src/nwfilter/nwfilter_gentech_driver.c @@ -463,7 +463,7 @@ virNWFilterDoInstantiate(virNWFilterTechDriver *techdriver, bool forceWithPendingReq) { int rc; - virNWFilterInst inst; + virNWFilterInst inst = { 0 }; bool instantiate = true; g_autofree char *buf = NULL; virNWFilterVarValue *lv; @@ -471,8 +471,6 @@ virNWFilterDoInstantiate(virNWFilterTechDriver *techdriver, bool reportIP = false; g_autoptr(GHashTable) missing_vars = virHashNew(virNWFilterVarValueHashFree); - memset(&inst, 0, sizeof(inst)); - rc = virNWFilterDetermineMissingVarsRec(filter, binding->filterparams, missing_vars, diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c index eda1308097..7fc412c17e 100644 --- a/src/qemu/qemu_agent.c +++ b/src/qemu/qemu_agent.c @@ -149,7 +149,7 @@ static void qemuAgentDispose(void *obj) static int qemuAgentOpenUnix(const char *socketpath) { - struct sockaddr_un addr; + struct sockaddr_un addr = { 0 }; int agentfd; if ((agentfd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) { @@ -165,7 +165,6 @@ qemuAgentOpenUnix(const char *socketpath) goto error; } - memset(&addr, 0, sizeof(addr)); addr.sun_family = AF_UNIX; if (virStrcpyStatic(addr.sun_path, socketpath) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -803,11 +802,9 @@ qemuAgentGuestSyncSend(qemuAgent *agent, g_autofree char *txMsg = NULL; g_autoptr(virJSONValue) rxObj = NULL; unsigned long long id; - qemuAgentMessage sync_msg; + qemuAgentMessage sync_msg = { 0 }; int rc; - memset(&sync_msg, 0, sizeof(sync_msg)); - if (virTimeMillisNow(&id) < 0) return -1; @@ -1015,12 +1012,11 @@ qemuAgentCommandFull(qemuAgent *agent, bool report_unsupported) { int ret = -1; - qemuAgentMessage msg; + qemuAgentMessage msg = { 0 }; g_autofree char *cmdstr = NULL; int await_event = agent->await_event; *reply = NULL; - memset(&msg, 0, sizeof(msg)); if (!agent->running) { virReportError(VIR_ERR_AGENT_UNRESPONSIVE, "%s", diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 64af0b5ea9..77c5335bde 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -4868,7 +4868,7 @@ qemuBuildSCSIHostdevDevProps(const virDomainDef *def, int qemuOpenChrChardevUNIXSocket(const virDomainChrSourceDef *dev) { - struct sockaddr_un addr; + struct sockaddr_un addr = { 0 }; socklen_t addrlen = sizeof(addr); int fd; @@ -4878,7 +4878,6 @@ qemuOpenChrChardevUNIXSocket(const virDomainChrSourceDef *dev) goto error; } - memset(&addr, 0, sizeof(addr)); addr.sun_family = AF_UNIX; if (virStrcpyStatic(addr.sun_path, dev->data.nix.path) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 1f388306f4..f8039160f4 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -14933,8 +14933,8 @@ qemuDomainSetBlockIoTune(virDomainPtr dom, qemuDomainObjPrivate *priv; virDomainDef *def = NULL; virDomainDef *persistentDef = NULL; - virDomainBlockIoTuneInfo info; - virDomainBlockIoTuneInfo conf_info; + virDomainBlockIoTuneInfo info = { 0 }; + virDomainBlockIoTuneInfo conf_info = { 0 }; int ret = -1; size_t i; virDomainDiskDef *conf_disk = NULL; @@ -14995,9 +14995,6 @@ qemuDomainSetBlockIoTune(virDomainPtr dom, NULL) < 0) return -1; - memset(&info, 0, sizeof(info)); - memset(&conf_info, 0, sizeof(conf_info)); - if (!(vm = qemuDomainObjFromDomain(dom))) return -1; diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index c680c4b804..db34b6c179 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -227,7 +227,7 @@ qemuMonitorDispose(void *obj) static int qemuMonitorOpenUnix(const char *monitor) { - struct sockaddr_un addr; + struct sockaddr_un addr = { 0 }; VIR_AUTOCLOSE monfd = -1; int ret = -1; @@ -237,7 +237,6 @@ qemuMonitorOpenUnix(const char *monitor) return -1; } - memset(&addr, 0, sizeof(addr)); addr.sun_family = AF_UNIX; if (virStrcpyStatic(addr.sun_path, monitor) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -309,13 +308,12 @@ qemuMonitorIOWriteWithFD(qemuMonitor *mon, size_t len, int fd) { - struct msghdr msg; + struct msghdr msg = { 0 }; struct iovec iov[1]; int ret; char control[CMSG_SPACE(sizeof(int))]; struct cmsghdr *cmsg; - memset(&msg, 0, sizeof(msg)); memset(control, 0, sizeof(control)); iov[0].iov_base = (void *)data; diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index d9e9a4481c..70536028ab 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -259,13 +259,11 @@ qemuMonitorJSONCommandWithFd(qemuMonitor *mon, virJSONValue **reply) { int ret = -1; - qemuMonitorMessage msg; + qemuMonitorMessage msg = { 0 }; g_auto(virBuffer) cmdbuf = VIR_BUFFER_INITIALIZER; *reply = NULL; - memset(&msg, 0, sizeof(msg)); - if (virJSONValueObjectHasKey(cmd, "execute")) { g_autofree char *id = qemuMonitorNextCommandID(mon); @@ -2035,10 +2033,9 @@ qemuMonitorJSONSetMemoryStatsPeriod(qemuMonitor *mon, char *balloonpath, int period) { - qemuMonitorJSONObjectProperty prop; + qemuMonitorJSONObjectProperty prop = { 0 }; /* Set to the value in memballoon (could enable or disable) */ - memset(&prop, 0, sizeof(qemuMonitorJSONObjectProperty)); prop.type = QEMU_MONITOR_OBJECT_PROPERTY_INT; prop.val.iv = period; if (qemuMonitorJSONSetObjectProperty(mon, balloonpath, diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index db06991450..572b842349 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -2226,14 +2226,13 @@ qemuRefreshRTC(virDomainObj *vm) { qemuDomainObjPrivate *priv = vm->privateData; time_t now, then; - struct tm thenbits; + struct tm thenbits = { 0 }; long localOffset; int rv; if (vm->def->clock.offset != VIR_DOMAIN_CLOCK_OFFSET_VARIABLE) return; - memset(&thenbits, 0, sizeof(thenbits)); qemuDomainObjEnterMonitor(vm); now = time(NULL); rv = qemuMonitorGetRTCTime(priv->mon, &thenbits); diff --git a/src/remote/remote_daemon_dispatch.c b/src/remote/remote_daemon_dispatch.c index 7144e9e7ca..2bb9e306a4 100644 --- a/src/remote/remote_daemon_dispatch.c +++ b/src/remote/remote_daemon_dispatch.c @@ -313,7 +313,7 @@ remoteRelayDomainEventLifecycle(virConnectPtr conn, void *opaque) { daemonClientEventCallback *callback = opaque; - remote_domain_event_lifecycle_msg data; + remote_domain_event_lifecycle_msg data = { 0 }; if (callback->callbackID < 0 || !remoteRelayDomainEventCheckACL(callback->client, conn, dom)) @@ -323,7 +323,6 @@ remoteRelayDomainEventLifecycle(virConnectPtr conn, event, detail, callback->callbackID, callback->legacy); /* build return data */ - memset(&data, 0, sizeof(data)); make_nonnull_domain(&data.dom, dom); data.event = event; data.detail = detail; @@ -352,7 +351,7 @@ remoteRelayDomainEventReboot(virConnectPtr conn, void *opaque) { daemonClientEventCallback *callback = opaque; - remote_domain_event_reboot_msg data; + remote_domain_event_reboot_msg data = { 0 }; if (callback->callbackID < 0 || !remoteRelayDomainEventCheckACL(callback->client, conn, dom)) @@ -362,7 +361,6 @@ remoteRelayDomainEventReboot(virConnectPtr conn, dom->name, dom->id, callback->callbackID, callback->legacy); /* build return data */ - memset(&data, 0, sizeof(data)); make_nonnull_domain(&data.dom, dom); if (callback->legacy) { @@ -389,7 +387,7 @@ remoteRelayDomainEventRTCChange(virConnectPtr conn, void *opaque) { daemonClientEventCallback *callback = opaque; - remote_domain_event_rtc_change_msg data; + remote_domain_event_rtc_change_msg data = { 0 }; if (callback->callbackID < 0 || !remoteRelayDomainEventCheckACL(callback->client, conn, dom)) @@ -400,7 +398,6 @@ remoteRelayDomainEventRTCChange(virConnectPtr conn, callback->callbackID, callback->legacy); /* build return data */ - memset(&data, 0, sizeof(data)); make_nonnull_domain(&data.dom, dom); data.offset = offset; @@ -428,7 +425,7 @@ remoteRelayDomainEventWatchdog(virConnectPtr conn, void *opaque) { daemonClientEventCallback *callback = opaque; - remote_domain_event_watchdog_msg data; + remote_domain_event_watchdog_msg data = { 0 }; if (callback->callbackID < 0 || !remoteRelayDomainEventCheckACL(callback->client, conn, dom)) @@ -438,7 +435,6 @@ remoteRelayDomainEventWatchdog(virConnectPtr conn, dom->name, dom->id, action, callback->callbackID); /* build return data */ - memset(&data, 0, sizeof(data)); make_nonnull_domain(&data.dom, dom); data.action = action; @@ -468,7 +464,7 @@ remoteRelayDomainEventIOError(virConnectPtr conn, void *opaque) { daemonClientEventCallback *callback = opaque; - remote_domain_event_io_error_msg data; + remote_domain_event_io_error_msg data = { 0 }; if (callback->callbackID < 0 || !remoteRelayDomainEventCheckACL(callback->client, conn, dom)) @@ -479,7 +475,6 @@ remoteRelayDomainEventIOError(virConnectPtr conn, callback->callbackID); /* build return data */ - memset(&data, 0, sizeof(data)); data.srcPath = g_strdup(srcPath); data.devAlias = g_strdup(devAlias); make_nonnull_domain(&data.dom, dom); @@ -512,7 +507,7 @@ remoteRelayDomainEventIOErrorReason(virConnectPtr conn, void *opaque) { daemonClientEventCallback *callback = opaque; - remote_domain_event_io_error_reason_msg data; + remote_domain_event_io_error_reason_msg data = { 0 }; if (callback->callbackID < 0 || !remoteRelayDomainEventCheckACL(callback->client, conn, dom)) @@ -523,7 +518,6 @@ remoteRelayDomainEventIOErrorReason(virConnectPtr conn, callback->callbackID); /* build return data */ - memset(&data, 0, sizeof(data)); data.srcPath = g_strdup(srcPath); data.devAlias = g_strdup(devAlias); data.reason = g_strdup(reason); @@ -558,7 +552,7 @@ remoteRelayDomainEventGraphics(virConnectPtr conn, void *opaque) { daemonClientEventCallback *callback = opaque; - remote_domain_event_graphics_msg data; + remote_domain_event_graphics_msg data = { 0 }; size_t i; if (callback->callbackID < 0 || @@ -576,7 +570,6 @@ remoteRelayDomainEventGraphics(virConnectPtr conn, VIR_DEBUG(" %s=%s", subject->identities[i].type, subject->identities[i].name); /* build return data */ - memset(&data, 0, sizeof(data)); data.phase = phase; data.local.family = local->family; data.remote.family = remote->family; @@ -625,7 +618,7 @@ remoteRelayDomainEventBlockJob(virConnectPtr conn, void *opaque) { daemonClientEventCallback *callback = opaque; - remote_domain_event_block_job_msg data; + remote_domain_event_block_job_msg data = { 0 }; if (callback->callbackID < 0 || !remoteRelayDomainEventCheckACL(callback->client, conn, dom)) @@ -635,7 +628,6 @@ remoteRelayDomainEventBlockJob(virConnectPtr conn, dom->name, dom->id, path, type, status, callback->callbackID); /* build return data */ - memset(&data, 0, sizeof(data)); data.path = g_strdup(path); data.type = type; data.status = status; @@ -664,7 +656,7 @@ remoteRelayDomainEventControlError(virConnectPtr conn, void *opaque) { daemonClientEventCallback *callback = opaque; - remote_domain_event_control_error_msg data; + remote_domain_event_control_error_msg data = { 0 }; if (callback->callbackID < 0 || !remoteRelayDomainEventCheckACL(callback->client, conn, dom)) @@ -674,7 +666,6 @@ remoteRelayDomainEventControlError(virConnectPtr conn, dom->name, dom->id, callback->callbackID); /* build return data */ - memset(&data, 0, sizeof(data)); make_nonnull_domain(&data.dom, dom); if (callback->legacy) { @@ -704,7 +695,7 @@ remoteRelayDomainEventDiskChange(virConnectPtr conn, void *opaque) { daemonClientEventCallback *callback = opaque; - remote_domain_event_disk_change_msg data; + remote_domain_event_disk_change_msg data = { 0 }; if (callback->callbackID < 0 || !remoteRelayDomainEventCheckACL(callback->client, conn, dom)) @@ -715,7 +706,6 @@ remoteRelayDomainEventDiskChange(virConnectPtr conn, callback->callbackID); /* build return data */ - memset(&data, 0, sizeof(data)); if (oldSrcPath) { data.oldSrcPath = g_new0(remote_nonnull_string, 1); *(data.oldSrcPath) = g_strdup(oldSrcPath); @@ -755,7 +745,7 @@ remoteRelayDomainEventTrayChange(virConnectPtr conn, void *opaque) { daemonClientEventCallback *callback = opaque; - remote_domain_event_tray_change_msg data; + remote_domain_event_tray_change_msg data = { 0 }; if (callback->callbackID < 0 || !remoteRelayDomainEventCheckACL(callback->client, conn, dom)) @@ -765,8 +755,6 @@ remoteRelayDomainEventTrayChange(virConnectPtr conn, dom->name, dom->id, devAlias, reason, callback->callbackID); /* build return data */ - memset(&data, 0, sizeof(data)); - data.devAlias = g_strdup(devAlias); data.reason = reason; make_nonnull_domain(&data.dom, dom); @@ -794,7 +782,7 @@ remoteRelayDomainEventPMWakeup(virConnectPtr conn, void *opaque) { daemonClientEventCallback *callback = opaque; - remote_domain_event_pmwakeup_msg data; + remote_domain_event_pmwakeup_msg data = { 0 }; if (callback->callbackID < 0 || !remoteRelayDomainEventCheckACL(callback->client, conn, dom)) @@ -804,7 +792,6 @@ remoteRelayDomainEventPMWakeup(virConnectPtr conn, dom->name, dom->id, callback->callbackID); /* build return data */ - memset(&data, 0, sizeof(data)); make_nonnull_domain(&data.dom, dom); if (callback->legacy) { @@ -830,7 +817,7 @@ remoteRelayDomainEventPMSuspend(virConnectPtr conn, void *opaque) { daemonClientEventCallback *callback = opaque; - remote_domain_event_pmsuspend_msg data; + remote_domain_event_pmsuspend_msg data = { 0 }; if (callback->callbackID < 0 || !remoteRelayDomainEventCheckACL(callback->client, conn, dom)) @@ -840,7 +827,6 @@ remoteRelayDomainEventPMSuspend(virConnectPtr conn, dom->name, dom->id, callback->callbackID); /* build return data */ - memset(&data, 0, sizeof(data)); make_nonnull_domain(&data.dom, dom); if (callback->legacy) { @@ -866,7 +852,7 @@ remoteRelayDomainEventBalloonChange(virConnectPtr conn, void *opaque) { daemonClientEventCallback *callback = opaque; - remote_domain_event_balloon_change_msg data; + remote_domain_event_balloon_change_msg data = { 0 }; if (callback->callbackID < 0 || !remoteRelayDomainEventCheckACL(callback->client, conn, dom)) @@ -876,7 +862,6 @@ remoteRelayDomainEventBalloonChange(virConnectPtr conn, dom->name, dom->id, actual, callback->callbackID); /* build return data */ - memset(&data, 0, sizeof(data)); make_nonnull_domain(&data.dom, dom); data.actual = actual; @@ -904,7 +889,7 @@ remoteRelayDomainEventPMSuspendDisk(virConnectPtr conn, void *opaque) { daemonClientEventCallback *callback = opaque; - remote_domain_event_pmsuspend_disk_msg data; + remote_domain_event_pmsuspend_disk_msg data = { 0 }; if (callback->callbackID < 0 || !remoteRelayDomainEventCheckACL(callback->client, conn, dom)) @@ -914,7 +899,6 @@ remoteRelayDomainEventPMSuspendDisk(virConnectPtr conn, dom->name, dom->id, callback->callbackID); /* build return data */ - memset(&data, 0, sizeof(data)); make_nonnull_domain(&data.dom, dom); if (callback->legacy) { @@ -940,7 +924,7 @@ remoteRelayDomainEventDeviceRemoved(virConnectPtr conn, void *opaque) { daemonClientEventCallback *callback = opaque; - remote_domain_event_device_removed_msg data; + remote_domain_event_device_removed_msg data = { 0 }; if (callback->callbackID < 0 || !remoteRelayDomainEventCheckACL(callback->client, conn, dom)) @@ -950,8 +934,6 @@ remoteRelayDomainEventDeviceRemoved(virConnectPtr conn, dom->name, dom->id, devAlias, callback->callbackID); /* build return data */ - memset(&data, 0, sizeof(data)); - data.devAlias = g_strdup(devAlias); make_nonnull_domain(&data.dom, dom); @@ -984,7 +966,7 @@ remoteRelayDomainEventBlockJob2(virConnectPtr conn, void *opaque) { daemonClientEventCallback *callback = opaque; - remote_domain_event_block_job_2_msg data; + remote_domain_event_block_job_2_msg data = { 0 }; if (callback->callbackID < 0 || !remoteRelayDomainEventCheckACL(callback->client, conn, dom)) @@ -994,7 +976,6 @@ remoteRelayDomainEventBlockJob2(virConnectPtr conn, dom->name, dom->id, dst, type, status, callback->callbackID); /* build return data */ - memset(&data, 0, sizeof(data)); data.callbackID = callback->callbackID; data.dst = g_strdup(dst); data.type = type; @@ -1017,7 +998,7 @@ remoteRelayDomainEventTunable(virConnectPtr conn, void *opaque) { daemonClientEventCallback *callback = opaque; - remote_domain_event_callback_tunable_msg data; + remote_domain_event_callback_tunable_msg data = { 0 }; if (callback->callbackID < 0 || !remoteRelayDomainEventCheckACL(callback->client, conn, dom)) @@ -1027,8 +1008,6 @@ remoteRelayDomainEventTunable(virConnectPtr conn, dom->name, dom->id, callback->callbackID, params, nparams); /* build return data */ - memset(&data, 0, sizeof(data)); - if (virTypedParamsSerialize(params, nparams, REMOTE_DOMAIN_EVENT_TUNABLE_MAX, (struct _virTypedParameterRemote **) &data.params.params_val, @@ -1057,7 +1036,7 @@ remoteRelayDomainEventAgentLifecycle(virConnectPtr conn, void *opaque) { daemonClientEventCallback *callback = opaque; - remote_domain_event_callback_agent_lifecycle_msg data; + remote_domain_event_callback_agent_lifecycle_msg data = { 0 }; if (callback->callbackID < 0 || !remoteRelayDomainEventCheckACL(callback->client, conn, dom)) @@ -1068,7 +1047,6 @@ remoteRelayDomainEventAgentLifecycle(virConnectPtr conn, dom->name, dom->id, callback->callbackID, state, reason); /* build return data */ - memset(&data, 0, sizeof(data)); data.callbackID = callback->callbackID; make_nonnull_domain(&data.dom, dom); data.state = state; @@ -1090,7 +1068,7 @@ remoteRelayDomainEventDeviceAdded(virConnectPtr conn, void *opaque) { daemonClientEventCallback *callback = opaque; - remote_domain_event_callback_device_added_msg data; + remote_domain_event_callback_device_added_msg data = { 0 }; if (callback->callbackID < 0 || !remoteRelayDomainEventCheckACL(callback->client, conn, dom)) @@ -1100,8 +1078,6 @@ remoteRelayDomainEventDeviceAdded(virConnectPtr conn, dom->name, dom->id, devAlias, callback->callbackID); /* build return data */ - memset(&data, 0, sizeof(data)); - data.devAlias = g_strdup(devAlias); make_nonnull_domain(&data.dom, dom); data.callbackID = callback->callbackID; @@ -1122,7 +1098,7 @@ remoteRelayDomainEventMigrationIteration(virConnectPtr conn, void *opaque) { daemonClientEventCallback *callback = opaque; - remote_domain_event_callback_migration_iteration_msg data; + remote_domain_event_callback_migration_iteration_msg data = { 0 }; if (callback->callbackID < 0 || !remoteRelayDomainEventCheckACL(callback->client, conn, dom)) @@ -1133,7 +1109,6 @@ remoteRelayDomainEventMigrationIteration(virConnectPtr conn, dom->name, dom->id, callback->callbackID, iteration); /* build return data */ - memset(&data, 0, sizeof(data)); data.callbackID = callback->callbackID; make_nonnull_domain(&data.dom, dom); @@ -1156,7 +1131,7 @@ remoteRelayDomainEventJobCompleted(virConnectPtr conn, void *opaque) { daemonClientEventCallback *callback = opaque; - remote_domain_event_callback_job_completed_msg data; + remote_domain_event_callback_job_completed_msg data = { 0 }; if (callback->callbackID < 0 || !remoteRelayDomainEventCheckACL(callback->client, conn, dom)) @@ -1167,8 +1142,6 @@ remoteRelayDomainEventJobCompleted(virConnectPtr conn, dom->name, dom->id, callback->callbackID, params, nparams); /* build return data */ - memset(&data, 0, sizeof(data)); - if (virTypedParamsSerialize(params, nparams, REMOTE_DOMAIN_JOB_STATS_MAX, (struct _virTypedParameterRemote **) &data.params.params_val, @@ -1194,7 +1167,7 @@ remoteRelayDomainEventDeviceRemovalFailed(virConnectPtr conn, void *opaque) { daemonClientEventCallback *callback = opaque; - remote_domain_event_callback_device_removal_failed_msg data; + remote_domain_event_callback_device_removal_failed_msg data = { 0 }; if (callback->callbackID < 0 || !remoteRelayDomainEventCheckACL(callback->client, conn, dom)) @@ -1204,8 +1177,6 @@ remoteRelayDomainEventDeviceRemovalFailed(virConnectPtr conn, dom->name, dom->id, devAlias, callback->callbackID); /* build return data */ - memset(&data, 0, sizeof(data)); - data.devAlias = g_strdup(devAlias); make_nonnull_domain(&data.dom, dom); @@ -1228,7 +1199,7 @@ remoteRelayDomainEventMetadataChange(virConnectPtr conn, void *opaque) { daemonClientEventCallback *callback = opaque; - remote_domain_event_callback_metadata_change_msg data; + remote_domain_event_callback_metadata_change_msg data = { 0 }; if (callback->callbackID < 0 || !remoteRelayDomainEventCheckACL(callback->client, conn, dom)) @@ -1238,8 +1209,6 @@ remoteRelayDomainEventMetadataChange(virConnectPtr conn, dom->name, dom->id, type, NULLSTR(nsuri), callback->callbackID); /* build return data */ - memset(&data, 0, sizeof(data)); - data.type = type; if (nsuri) { data.nsuri = g_new0(remote_nonnull_string, 1); @@ -1268,7 +1237,7 @@ remoteRelayDomainEventBlockThreshold(virConnectPtr conn, void *opaque) { daemonClientEventCallback *callback = opaque; - remote_domain_event_block_threshold_msg data; + remote_domain_event_block_threshold_msg data = { 0 }; if (callback->callbackID < 0 || !remoteRelayDomainEventCheckACL(callback->client, conn, dom)) @@ -1278,7 +1247,6 @@ remoteRelayDomainEventBlockThreshold(virConnectPtr conn, dom->name, dom->id, dev, NULLSTR(path), threshold, excess, callback->callbackID); /* build return data */ - memset(&data, 0, sizeof(data)); data.callbackID = callback->callbackID; data.dev = g_strdup(dev); if (path) { @@ -1306,14 +1274,13 @@ remoteRelayDomainEventMemoryFailure(virConnectPtr conn, void *opaque) { daemonClientEventCallback *callback = opaque; - remote_domain_event_memory_failure_msg data; + remote_domain_event_memory_failure_msg data = { 0 }; if (callback->callbackID < 0 || !remoteRelayDomainEventCheckACL(callback->client, conn, dom)) return -1; /* build return data */ - memset(&data, 0, sizeof(data)); data.callbackID = callback->callbackID; data.recipient = recipient; data.action = action; @@ -1336,14 +1303,13 @@ remoteRelayDomainEventMemoryDeviceSizeChange(virConnectPtr conn, void *opaque) { daemonClientEventCallback *callback = opaque; - remote_domain_event_memory_device_size_change_msg data; + remote_domain_event_memory_device_size_change_msg data = { 0 }; if (callback->callbackID < 0 || !remoteRelayDomainEventCheckACL(callback->client, conn, dom)) return -1; /* build return data */ - memset(&data, 0, sizeof(data)); data.callbackID = callback->callbackID; data.alias = g_strdup(alias); data.size = size; @@ -1397,7 +1363,7 @@ remoteRelayNetworkEventLifecycle(virConnectPtr conn, void *opaque) { daemonClientEventCallback *callback = opaque; - remote_network_event_lifecycle_msg data; + remote_network_event_lifecycle_msg data = { 0 }; if (callback->callbackID < 0 || !remoteRelayNetworkEventCheckACL(callback->client, conn, net)) @@ -1407,7 +1373,6 @@ remoteRelayNetworkEventLifecycle(virConnectPtr conn, event, detail, callback->callbackID); /* build return data */ - memset(&data, 0, sizeof(data)); make_nonnull_network(&data.net, net); data.callbackID = callback->callbackID; data.event = event; @@ -1434,7 +1399,7 @@ remoteRelayStoragePoolEventLifecycle(virConnectPtr conn, void *opaque) { daemonClientEventCallback *callback = opaque; - remote_storage_pool_event_lifecycle_msg data; + remote_storage_pool_event_lifecycle_msg data = { 0 }; if (callback->callbackID < 0 || !remoteRelayStoragePoolEventCheckACL(callback->client, conn, pool)) @@ -1444,7 +1409,6 @@ remoteRelayStoragePoolEventLifecycle(virConnectPtr conn, event, detail, callback->callbackID); /* build return data */ - memset(&data, 0, sizeof(data)); make_nonnull_storage_pool(&data.pool, pool); data.callbackID = callback->callbackID; data.event = event; @@ -1464,7 +1428,7 @@ remoteRelayStoragePoolEventRefresh(virConnectPtr conn, void *opaque) { daemonClientEventCallback *callback = opaque; - remote_storage_pool_event_refresh_msg data; + remote_storage_pool_event_refresh_msg data = { 0 }; if (callback->callbackID < 0 || !remoteRelayStoragePoolEventCheckACL(callback->client, conn, pool)) @@ -1474,7 +1438,6 @@ remoteRelayStoragePoolEventRefresh(virConnectPtr conn, callback->callbackID); /* build return data */ - memset(&data, 0, sizeof(data)); make_nonnull_storage_pool(&data.pool, pool); data.callbackID = callback->callbackID; @@ -1501,7 +1464,7 @@ remoteRelayNodeDeviceEventLifecycle(virConnectPtr conn, void *opaque) { daemonClientEventCallback *callback = opaque; - remote_node_device_event_lifecycle_msg data; + remote_node_device_event_lifecycle_msg data = { 0 }; if (callback->callbackID < 0 || !remoteRelayNodeDeviceEventCheckACL(callback->client, conn, dev)) @@ -1511,7 +1474,6 @@ remoteRelayNodeDeviceEventLifecycle(virConnectPtr conn, event, detail, callback->callbackID); /* build return data */ - memset(&data, 0, sizeof(data)); make_nonnull_node_device(&data.dev, dev); data.callbackID = callback->callbackID; data.event = event; @@ -1531,7 +1493,7 @@ remoteRelayNodeDeviceEventUpdate(virConnectPtr conn, void *opaque) { daemonClientEventCallback *callback = opaque; - remote_node_device_event_update_msg data; + remote_node_device_event_update_msg data = { 0 }; if (callback->callbackID < 0 || !remoteRelayNodeDeviceEventCheckACL(callback->client, conn, dev)) @@ -1541,7 +1503,6 @@ remoteRelayNodeDeviceEventUpdate(virConnectPtr conn, callback->callbackID); /* build return data */ - memset(&data, 0, sizeof(data)); make_nonnull_node_device(&data.dev, dev); data.callbackID = callback->callbackID; @@ -1568,7 +1529,7 @@ remoteRelaySecretEventLifecycle(virConnectPtr conn, void *opaque) { daemonClientEventCallback *callback = opaque; - remote_secret_event_lifecycle_msg data; + remote_secret_event_lifecycle_msg data = { 0 }; if (callback->callbackID < 0 || !remoteRelaySecretEventCheckACL(callback->client, conn, secret)) @@ -1578,7 +1539,6 @@ remoteRelaySecretEventLifecycle(virConnectPtr conn, event, detail, callback->callbackID); /* build return data */ - memset(&data, 0, sizeof(data)); make_nonnull_secret(&data.secret, secret); data.callbackID = callback->callbackID; data.event = event; @@ -1598,7 +1558,7 @@ remoteRelaySecretEventValueChanged(virConnectPtr conn, void *opaque) { daemonClientEventCallback *callback = opaque; - remote_secret_event_value_changed_msg data; + remote_secret_event_value_changed_msg data = { 0 }; if (callback->callbackID < 0 || !remoteRelaySecretEventCheckACL(callback->client, conn, secret)) @@ -1608,7 +1568,6 @@ remoteRelaySecretEventValueChanged(virConnectPtr conn, callback->callbackID); /* build return data */ - memset(&data, 0, sizeof(data)); make_nonnull_secret(&data.secret, secret); data.callbackID = callback->callbackID; @@ -1637,7 +1596,7 @@ remoteRelayDomainQemuMonitorEvent(virConnectPtr conn, void *opaque) { daemonClientEventCallback *callback = opaque; - qemu_domain_monitor_event_msg data; + qemu_domain_monitor_event_msg data = { 0 }; if (callback->callbackID < 0 || !remoteRelayDomainQemuMonitorEventCheckACL(callback->client, conn, @@ -1648,7 +1607,6 @@ remoteRelayDomainQemuMonitorEvent(virConnectPtr conn, event, details, callback->callbackID); /* build return data */ - memset(&data, 0, sizeof(data)); data.callbackID = callback->callbackID; data.event = g_strdup(event); data.seconds = seconds; @@ -2677,14 +2635,13 @@ remoteDispatchNodeGetSecurityModel(virNetServer *server G_GNUC_UNUSED, struct virNetMessageError *rerr, remote_node_get_security_model_ret *ret) { - virSecurityModel secmodel; + virSecurityModel secmodel = { 0 }; int rv = -1; virConnectPtr conn = remoteGetHypervisorConn(client); if (!conn) goto cleanup; - memset(&secmodel, 0, sizeof(secmodel)); if (virNodeGetSecurityModel(conn, &secmodel) < 0) goto cleanup; diff --git a/src/remote/remote_daemon_stream.c b/src/remote/remote_daemon_stream.c index f52af790c1..1a89ff822c 100644 --- a/src/remote/remote_daemon_stream.c +++ b/src/remote/remote_daemon_stream.c @@ -226,12 +226,11 @@ daemonStreamEvent(virStreamPtr st, int events, void *opaque) (events & (VIR_STREAM_EVENT_ERROR | VIR_STREAM_EVENT_HANGUP))) { int ret; virNetMessage *msg; - virNetMessageError rerr; + virNetMessageError rerr = { 0 }; virErrorPtr origErr; virErrorPreserveLast(&origErr); - memset(&rerr, 0, sizeof(rerr)); stream->closed = true; virStreamEventRemoveCallback(stream->st); virStreamAbort(stream->st); @@ -565,13 +564,11 @@ daemonStreamHandleWriteData(virNetServerClient *client, /* Blocking, so indicate we have more todo later */ return 1; } else if (ret < 0) { - virNetMessageError rerr; + virNetMessageError rerr = { 0 }; virErrorPtr err; virErrorPreserveLast(&err); - memset(&rerr, 0, sizeof(rerr)); - VIR_INFO("Stream send failed"); stream->closed = true; virStreamEventRemoveCallback(stream->st); @@ -613,8 +610,8 @@ daemonStreamHandleFinish(virNetServerClient *client, ret = virStreamFinish(stream->st); if (ret < 0) { - virNetMessageError rerr; - memset(&rerr, 0, sizeof(rerr)); + virNetMessageError rerr = { 0 }; + return virNetServerProgramSendReplyError(stream->prog, client, msg, @@ -663,8 +660,8 @@ daemonStreamHandleAbort(virNetServerClient *client, } if (raise_error) { - virNetMessageError rerr; - memset(&rerr, 0, sizeof(rerr)); + virNetMessageError rerr = { 0 }; + return virNetServerProgramSendReplyError(stream->prog, client, msg, @@ -709,9 +706,7 @@ daemonStreamHandleHole(virNetServerClient *client, ret = virStreamSendHole(stream->st, data.length, data.flags); if (ret < 0) { - virNetMessageError rerr; - - memset(&rerr, 0, sizeof(rerr)); + virNetMessageError rerr = { 0 }; VIR_INFO("Stream send hole failed"); stream->closed = true; @@ -825,7 +820,7 @@ daemonStreamHandleRead(virNetServerClient *client, daemonClientStream *stream) { virNetMessage *msg = NULL; - virNetMessageError rerr; + virNetMessageError rerr = { 0 }; char *buffer; size_t bufferLen = VIR_NET_MESSAGE_LEGACY_PAYLOAD_MAX; int ret = -1; @@ -848,8 +843,6 @@ daemonStreamHandleRead(virNetServerClient *client, if (!stream->tx) return 0; - memset(&rerr, 0, sizeof(rerr)); - buffer = g_new0(char, bufferLen); if (!(msg = virNetMessageNew(false))) diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index 7ccf550dff..8e78af0ea0 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -1184,10 +1184,9 @@ doRemoteOpen(virConnectPtr conn, /* Now try and find out what URI the daemon used */ if (conn->uri == NULL) { - remote_connect_get_uri_ret uriret; + remote_connect_get_uri_ret uriret = { 0 }; VIR_DEBUG("Trying to query remote URI"); - memset(&uriret, 0, sizeof(uriret)); if (call(conn, priv, 0, REMOTE_PROC_CONNECT_GET_URI, (xdrproc_t) xdr_void, (char *) NULL, @@ -3725,9 +3724,9 @@ static int remoteAuthSASL(virConnectPtr conn, struct private_data *priv, virConnectAuthPtr auth, const char *wantmech) { - remote_auth_sasl_init_ret iret; + remote_auth_sasl_init_ret iret = { 0 }; remote_auth_sasl_start_args sargs = {0}; - remote_auth_sasl_start_ret sret; + remote_auth_sasl_start_ret sret = { 0 }; const char *clientout; char *serverin = NULL; size_t clientoutlen, serverinlen; @@ -3739,9 +3738,7 @@ remoteAuthSASL(virConnectPtr conn, struct private_data *priv, const char *mechlist; virNetSASLContext *saslCtxt; virNetSASLSession *sasl = NULL; - struct remoteAuthInteractState state; - - memset(&state, 0, sizeof(state)); + struct remoteAuthInteractState state = { 0 }; VIR_DEBUG("Client initialize SASL authentication"); @@ -3787,7 +3784,6 @@ remoteAuthSASL(virConnectPtr conn, struct private_data *priv, goto cleanup; /* First call is to inquire about supported mechanisms in the server */ - memset(&iret, 0, sizeof(iret)); if (call(conn, priv, 0, REMOTE_PROC_AUTH_SASL_INIT, (xdrproc_t) xdr_void, (char *)NULL, (xdrproc_t) xdr_remote_auth_sasl_init_ret, (char *) &iret) != 0) @@ -3841,7 +3837,6 @@ remoteAuthSASL(virConnectPtr conn, struct private_data *priv, mech, clientoutlen, clientout); /* Now send the initial auth data to the server */ - memset(&sret, 0, sizeof(sret)); if (call(conn, priv, 0, REMOTE_PROC_AUTH_SASL_START, (xdrproc_t) xdr_remote_auth_sasl_start_args, (char *) &sargs, (xdrproc_t) xdr_remote_auth_sasl_start_ret, (char *) &sret) != 0) diff --git a/src/rpc/virnetclientprogram.c b/src/rpc/virnetclientprogram.c index abc8e6798a..31eee72fc8 100644 --- a/src/rpc/virnetclientprogram.c +++ b/src/rpc/virnetclientprogram.c @@ -116,11 +116,9 @@ static int virNetClientProgramDispatchError(virNetClientProgram *prog G_GNUC_UNUSED, virNetMessage *msg) { - virNetMessageError err; + virNetMessageError err = { 0 }; int ret = -1; - memset(&err, 0, sizeof(err)); - if (virNetMessageDecodePayload(msg, (xdrproc_t)xdr_virNetMessageError, &err) < 0) goto cleanup; diff --git a/src/rpc/virnetclientstream.c b/src/rpc/virnetclientstream.c index 21e9332134..98034d737d 100644 --- a/src/rpc/virnetclientstream.c +++ b/src/rpc/virnetclientstream.c @@ -261,7 +261,7 @@ void virNetClientStreamSetClosed(virNetClientStream *st, int virNetClientStreamSetError(virNetClientStream *st, virNetMessage *msg) { - virNetMessageError err; + virNetMessageError err = { 0 }; int ret = -1; virObjectLock(st); @@ -270,7 +270,6 @@ int virNetClientStreamSetError(virNetClientStream *st, VIR_DEBUG("Overwriting existing stream error %s", NULLSTR(st->err.message)); virResetError(&st->err); - memset(&err, 0, sizeof(err)); if (virNetMessageDecodePayload(msg, (xdrproc_t)xdr_virNetMessageError, &err) < 0) goto cleanup; @@ -444,13 +443,12 @@ virNetClientStreamHandleHole(virNetClient *client, virNetClientStream *st) { virNetMessage *msg; - virNetStreamHole data; + virNetStreamHole data = { 0 }; int ret = -1; VIR_DEBUG("client=%p st=%p", client, st); msg = st->rx; - memset(&data, 0, sizeof(data)); /* We should not be called unless there's VIR_NET_STREAM_HOLE * message at the head of the list. But doesn't hurt to check */ @@ -634,7 +632,7 @@ virNetClientStreamSendHole(virNetClientStream *st, unsigned int flags) { virNetMessage *msg = NULL; - virNetStreamHole data; + virNetStreamHole data = { 0 }; int ret = -1; VIR_DEBUG("st=%p length=%llu", st, length); @@ -645,7 +643,6 @@ virNetClientStreamSendHole(virNetClientStream *st, return -1; } - memset(&data, 0, sizeof(data)); data.length = length; data.flags = flags; diff --git a/src/rpc/virnetdaemon.c b/src/rpc/virnetdaemon.c index d37984d207..9795418126 100644 --- a/src/rpc/virnetdaemon.c +++ b/src/rpc/virnetdaemon.c @@ -692,7 +692,7 @@ virNetDaemonAddSignalHandler(virNetDaemon *dmn, void *opaque) { g_autofree virNetDaemonSignal *sigdata = NULL; - struct sigaction sig_action; + struct sigaction sig_action = { 0 }; VIR_LOCK_GUARD lock = virObjectLockGuard(dmn); if (virNetDaemonSignalSetup(dmn) < 0) @@ -706,7 +706,6 @@ virNetDaemonAddSignalHandler(virNetDaemon *dmn, sigdata->func = func; sigdata->opaque = opaque; - memset(&sig_action, 0, sizeof(sig_action)); sig_action.sa_sigaction = virNetDaemonSignalHandler; sig_action.sa_flags = SA_SIGINFO; sigemptyset(&sig_action.sa_mask); diff --git a/src/rpc/virnetsaslcontext.c b/src/rpc/virnetsaslcontext.c index 7151225cc3..8692703117 100644 --- a/src/rpc/virnetsaslcontext.c +++ b/src/rpc/virnetsaslcontext.c @@ -331,7 +331,7 @@ int virNetSASLSessionSecProps(virNetSASLSession *sasl, int maxSSF, bool allowAnonymous) { - sasl_security_properties_t secprops; + sasl_security_properties_t secprops = { 0 }; int err; int ret = -1; @@ -339,7 +339,6 @@ int virNetSASLSessionSecProps(virNetSASLSession *sasl, minSSF, maxSSF, allowAnonymous, sasl->maxbufsize); virObjectLock(sasl); - memset(&secprops, 0, sizeof(secprops)); secprops.min_ssf = minSSF; secprops.max_ssf = maxSSF; diff --git a/src/rpc/virnetserverprogram.c b/src/rpc/virnetserverprogram.c index 2cce188a09..b1236bf49b 100644 --- a/src/rpc/virnetserverprogram.c +++ b/src/rpc/virnetserverprogram.c @@ -229,12 +229,11 @@ int virNetServerProgramUnknownError(virNetServerClient *client, virNetMessage *msg, struct virNetMessageHeader *req) { - virNetMessageError rerr; + virNetMessageError rerr = { 0 }; virReportError(VIR_ERR_RPC, _("Cannot find program %1$d version %2$d"), req->prog, req->vers); - memset(&rerr, 0, sizeof(rerr)); return virNetServerProgramSendError(req->prog, req->vers, client, @@ -273,9 +272,7 @@ int virNetServerProgramDispatch(virNetServerProgram *prog, virNetMessage *msg) { int ret = -1; - virNetMessageError rerr; - - memset(&rerr, 0, sizeof(rerr)); + virNetMessageError rerr = { 0 }; VIR_DEBUG("prog=%d ver=%d type=%d status=%d serial=%u proc=%d", msg->header.prog, msg->header.vers, msg->header.type, @@ -369,12 +366,10 @@ virNetServerProgramDispatchCall(virNetServerProgram *prog, g_autofree char *ret = NULL; int rv = -1; virNetServerProgramProc *dispatcher = NULL; - virNetMessageError rerr; + virNetMessageError rerr = { 0 }; size_t i; g_autoptr(virIdentity) identity = NULL; - memset(&rerr, 0, sizeof(rerr)); - if (msg->header.status != VIR_NET_OK) { virReportError(VIR_ERR_RPC, _("Unexpected message status %1$u"), @@ -533,11 +528,10 @@ int virNetServerProgramSendStreamHole(virNetServerProgram *prog, long long length, unsigned int flags) { - virNetStreamHole data; + virNetStreamHole data = { 0 }; VIR_DEBUG("client=%p msg=%p length=%lld", client, msg, length); - memset(&data, 0, sizeof(data)); data.length = length; data.flags = flags; diff --git a/src/rpc/virnetsocket.c b/src/rpc/virnetsocket.c index 910fb8dd67..b58f7a6b8f 100644 --- a/src/rpc/virnetsocket.c +++ b/src/rpc/virnetsocket.c @@ -143,11 +143,10 @@ virNetSocketCheckProtocolByLookup(const char *address, int family, bool *hasFamily) { - struct addrinfo hints; + struct addrinfo hints = { 0 }; struct addrinfo *ai = NULL; int gaierr; - memset(&hints, 0, sizeof(hints)); hints.ai_family = family; hints.ai_flags = AI_PASSIVE | AI_ADDRCONFIG; hints.ai_socktype = SOCK_STREAM; @@ -313,7 +312,7 @@ int virNetSocketNewListenTCP(const char *nodename, virNetSocket **socks = NULL; size_t nsocks = 0; struct addrinfo *ai = NULL; - struct addrinfo hints; + struct addrinfo hints = { 0 }; int fd = -1; size_t i; int socketErrno = 0; @@ -326,7 +325,6 @@ int virNetSocketNewListenTCP(const char *nodename, *retsocks = NULL; *nretsocks = 0; - memset(&hints, 0, sizeof(hints)); hints.ai_family = family; hints.ai_flags = AI_PASSIVE; hints.ai_socktype = SOCK_STREAM; @@ -353,9 +351,7 @@ int virNetSocketNewListenTCP(const char *nodename, runp = ai; while (runp) { - virSocketAddr addr; - - memset(&addr, 0, sizeof(addr)); + virSocketAddr addr = { 0 }; if ((fd = socket(runp->ai_family, runp->ai_socktype, runp->ai_protocol)) < 0) { @@ -477,14 +473,12 @@ int virNetSocketNewListenUNIX(const char *path, gid_t grp, virNetSocket **retsock) { - virSocketAddr addr; + virSocketAddr addr = { 0 }; mode_t oldmask; int fd; *retsock = NULL; - memset(&addr, 0, sizeof(addr)); - addr.len = sizeof(addr.data.un); if ((fd = socket(PF_UNIX, SOCK_STREAM, 0)) < 0) { @@ -553,11 +547,9 @@ int virNetSocketNewListenFD(int fd, bool unlinkUNIX, virNetSocket **retsock) { - virSocketAddr addr; + virSocketAddr addr = { 0 }; *retsock = NULL; - memset(&addr, 0, sizeof(addr)); - addr.len = sizeof(addr.data); if (getsockname(fd, &addr.data.sa, &addr.len) < 0) { virReportSystemError(errno, "%s", _("Unable to get local socket name")); @@ -577,20 +569,16 @@ int virNetSocketNewConnectTCP(const char *nodename, virNetSocket **retsock) { struct addrinfo *ai = NULL; - struct addrinfo hints; + struct addrinfo hints = { 0 }; int fd = -1; - virSocketAddr localAddr; - virSocketAddr remoteAddr; + virSocketAddr localAddr = { 0 }; + virSocketAddr remoteAddr = { 0 }; struct addrinfo *runp; int savedErrno = ENOENT; int e; *retsock = NULL; - memset(&localAddr, 0, sizeof(localAddr)); - memset(&remoteAddr, 0, sizeof(remoteAddr)); - - memset(&hints, 0, sizeof(hints)); hints.ai_family = family; hints.ai_flags = AI_PASSIVE | AI_ADDRCONFIG | AI_V4MAPPED; hints.ai_socktype = SOCK_STREAM; @@ -666,17 +654,14 @@ int virNetSocketNewConnectUNIX(const char *path, VIR_AUTOCLOSE lockfd = -1; int fd = -1; int retries = 500; - virSocketAddr localAddr; - virSocketAddr remoteAddr; + virSocketAddr localAddr = { 0 }; + virSocketAddr remoteAddr = { 0 }; g_autofree char *rundir = NULL; int ret = -1; bool daemonLaunched = false; VIR_DEBUG("path=%s spawnDaemonPath=%s", path, NULLSTR(spawnDaemonPath)); - memset(&localAddr, 0, sizeof(localAddr)); - memset(&remoteAddr, 0, sizeof(remoteAddr)); - remoteAddr.len = sizeof(remoteAddr.data.un); if (spawnDaemonPath) { @@ -1168,8 +1153,8 @@ int virNetSocketNewConnectSockFD(int sockfd, virNetSocket *virNetSocketNewPostExecRestart(virJSONValue *object) { - virSocketAddr localAddr; - virSocketAddr remoteAddr; + virSocketAddr localAddr = { 0 }; + virSocketAddr remoteAddr = { 0 }; int fd, thepid, errfd; bool isClient; bool unlinkUNIX; @@ -1201,9 +1186,6 @@ virNetSocket *virNetSocketNewPostExecRestart(virJSONValue *object) if (virJSONValueObjectGetBoolean(object, "unlinkUNIX", &unlinkUNIX) < 0) unlinkUNIX = !isClient; - memset(&localAddr, 0, sizeof(localAddr)); - memset(&remoteAddr, 0, sizeof(remoteAddr)); - remoteAddr.len = sizeof(remoteAddr.data.stor); if (getsockname(fd, &remoteAddr.data.sa, &remoteAddr.len) < 0) { virReportSystemError(errno, "%s", _("Unable to get peer socket name")); @@ -2059,17 +2041,14 @@ int virNetSocketListen(virNetSocket *sock, int backlog) int virNetSocketAccept(virNetSocket *sock, virNetSocket **clientsock) { int fd = -1; - virSocketAddr localAddr; - virSocketAddr remoteAddr; + virSocketAddr localAddr = { 0 }; + virSocketAddr remoteAddr = { 0 }; int ret = -1; virObjectLock(sock); *clientsock = NULL; - memset(&localAddr, 0, sizeof(localAddr)); - memset(&remoteAddr, 0, sizeof(remoteAddr)); - remoteAddr.len = sizeof(remoteAddr.data.stor); if ((fd = accept(sock->fd, &remoteAddr.data.sa, &remoteAddr.len)) < 0) { if (errno == ECONNABORTED || diff --git a/src/rpc/virnetsshsession.c b/src/rpc/virnetsshsession.c index 98be120a11..16d420467e 100644 --- a/src/rpc/virnetsshsession.c +++ b/src/rpc/virnetsshsession.c @@ -559,7 +559,7 @@ static int virNetSSHAuthenticatePrivkey(virNetSSHSession *sess, virNetSSHAuthMethod *priv) { - virConnectCredential retr_passphrase; + virConnectCredential retr_passphrase = { 0 }; size_t i; char *errmsg; int ret; @@ -594,7 +594,6 @@ virNetSSHAuthenticatePrivkey(virNetSSHSession *sess, return -1; } - memset(&retr_passphrase, 0, sizeof(virConnectCredential)); retr_passphrase.type = -1; for (i = 0; i < sess->cred->ncredtype; i++) { diff --git a/src/storage/storage_backend_logical.c b/src/storage/storage_backend_logical.c index 60dc68cf4b..9462ac6790 100644 --- a/src/storage/storage_backend_logical.c +++ b/src/storage/storage_backend_logical.c @@ -186,11 +186,9 @@ virStorageBackendLogicalParseVolExtents(virStorageVolDef *vol, */ for (i = 0; i < nextents; i++) { g_autofree char *offset_str = NULL; - virStorageVolSourceExtent extent; + virStorageVolSourceExtent extent = { 0 }; size_t j = (i * 2) + 1; - memset(&extent, 0, sizeof(extent)); - offset_str = g_match_info_fetch(info, j + 1); if (virStrToLong_ull(offset_str, NULL, 10, &offset) < 0) { @@ -503,13 +501,12 @@ static char * virStorageBackendLogicalFindPoolSources(const char *srcSpec G_GNUC_UNUSED, unsigned int flags) { - virStoragePoolSourceList sourceList; + virStoragePoolSourceList sourceList = { 0 }; size_t i; char *retval = NULL; virCheckFlags(0, NULL); - memset(&sourceList, 0, sizeof(sourceList)); sourceList.type = VIR_STORAGE_POOL_LOGICAL; if (virStorageBackendLogicalGetPoolSources(&sourceList) < 0) @@ -549,13 +546,12 @@ static bool virStorageBackendLogicalMatchPoolSource(virStoragePoolObj *pool) { virStoragePoolDef *def = virStoragePoolObjGetDef(pool); - virStoragePoolSourceList sourceList; + virStoragePoolSourceList sourceList = { 0 }; virStoragePoolSource *thisSource = NULL; size_t i, j; int matchcount = 0; bool ret = false; - memset(&sourceList, 0, sizeof(sourceList)); sourceList.type = VIR_STORAGE_POOL_LOGICAL; if (virStorageBackendLogicalGetPoolSources(&sourceList) < 0) diff --git a/src/util/virarptable.c b/src/util/virarptable.c index 7f9fefc160..299dddd664 100644 --- a/src/util/virarptable.c +++ b/src/util/virarptable.c @@ -111,13 +111,12 @@ virArpTableGet(void) if (tb[NDA_DST]) { g_autofree char *ipstr = NULL; - virSocketAddr virAddr; + virSocketAddr virAddr = { 0 }; VIR_REALLOC_N(table->t, num + 1); table->n = num + 1; addr = RTA_DATA(tb[NDA_DST]); - memset(&virAddr, 0, sizeof(virAddr)); virAddr.len = sizeof(virAddr.data.inet4); virAddr.data.inet4.sin_family = AF_INET; virAddr.data.inet4.sin_addr = *(struct in_addr *)addr; diff --git a/src/util/virauth.c b/src/util/virauth.c index bd676858ce..e7a5f7f010 100644 --- a/src/util/virauth.c +++ b/src/util/virauth.c @@ -135,7 +135,7 @@ virAuthGetUsernamePath(const char *path, const char *hostname) { unsigned int ncred; - virConnectCredential cred; + virConnectCredential cred = { 0 }; g_autofree char *prompt = NULL; char *ret = NULL; @@ -150,8 +150,6 @@ virAuthGetUsernamePath(const char *path, return NULL; } - memset(&cred, 0, sizeof(virConnectCredential)); - if (defaultUsername != NULL) { prompt = g_strdup_printf(_("Enter username for %1$s [%2$s]"), hostname, defaultUsername); diff --git a/src/util/virbpf.c b/src/util/virbpf.c index 34abf6f9b4..78fa102b4d 100644 --- a/src/util/virbpf.c +++ b/src/util/virbpf.c @@ -35,9 +35,7 @@ virBPFCreateMap(unsigned int mapType, unsigned int valSize, unsigned int maxEntries) { - union bpf_attr attr; - - memset(&attr, 0, sizeof(attr)); + union bpf_attr attr = { 0 }; attr.map_type = mapType; attr.key_size = keySize; @@ -57,12 +55,10 @@ virBPFLoadProg(struct bpf_insn *insns, { g_autofree char *logbuf = NULL; int progfd = -1; - union bpf_attr attr; + union bpf_attr attr = { 0 }; logbuf = g_new0(char, LOG_BUF_SIZE); - memset(&attr, 0, sizeof(attr)); - attr.prog_type = progType; attr.insn_cnt = insnCnt; attr.insns = (uintptr_t)insns; @@ -85,9 +81,7 @@ virBPFAttachProg(int progfd, int targetfd, int attachType) { - union bpf_attr attr; - - memset(&attr, 0, sizeof(attr)); + union bpf_attr attr = { 0 }; attr.target_fd = targetfd; attr.attach_bpf_fd = progfd; @@ -102,9 +96,7 @@ virBPFDetachProg(int progfd, int targetfd, int attachType) { - union bpf_attr attr; - - memset(&attr, 0, sizeof(attr)); + union bpf_attr attr = { 0 }; attr.target_fd = targetfd; attr.attach_bpf_fd = progfd; @@ -121,11 +113,9 @@ virBPFQueryProg(int targetfd, unsigned int *progcnt, void *progids) { - union bpf_attr attr; + union bpf_attr attr = { 0 }; int rc; - memset(&attr, 0, sizeof(attr)); - attr.query.target_fd = targetfd; attr.query.attach_type = attachType; attr.query.prog_cnt = maxprogids; @@ -143,9 +133,7 @@ virBPFQueryProg(int targetfd, int virBPFGetProg(unsigned int id) { - union bpf_attr attr; - - memset(&attr, 0, sizeof(attr)); + union bpf_attr attr = { 0 }; attr.prog_id = id; @@ -158,11 +146,9 @@ virBPFGetProgInfo(int progfd, struct bpf_prog_info *info, unsigned int **mapIDs) { - union bpf_attr attr; + union bpf_attr attr = { 0 }; int rc; - memset(&attr, 0, sizeof(attr)); - attr.info.bpf_fd = progfd; attr.info.info_len = sizeof(struct bpf_prog_info); attr.info.info = (uintptr_t)info; @@ -200,9 +186,7 @@ virBPFGetProgInfo(int progfd, int virBPFGetMap(unsigned int id) { - union bpf_attr attr; - - memset(&attr, 0, sizeof(attr)); + union bpf_attr attr = { 0 }; attr.map_id = id; @@ -214,9 +198,7 @@ int virBPFGetMapInfo(int mapfd, struct bpf_map_info *info) { - union bpf_attr attr; - - memset(&attr, 0, sizeof(attr)); + union bpf_attr attr = { 0 }; attr.info.bpf_fd = mapfd; attr.info.info_len = sizeof(struct bpf_map_info); @@ -231,9 +213,7 @@ virBPFLookupElem(int mapfd, void *key, void *val) { - union bpf_attr attr; - - memset(&attr, 0, sizeof(attr)); + union bpf_attr attr = { 0 }; attr.map_fd = mapfd; attr.key = (uintptr_t)key; @@ -248,9 +228,7 @@ virBPFGetNextElem(int mapfd, void *key, void *nextKey) { - union bpf_attr attr; - - memset(&attr, 0, sizeof(attr)); + union bpf_attr attr = { 0 }; attr.map_fd = mapfd; attr.key = (uintptr_t)key; @@ -265,9 +243,7 @@ virBPFUpdateElem(int mapfd, void *key, void *val) { - union bpf_attr attr; - - memset(&attr, 0, sizeof(attr)); + union bpf_attr attr = { 0 }; attr.map_fd = mapfd; attr.key = (uintptr_t)key; @@ -281,9 +257,7 @@ int virBPFDeleteElem(int mapfd, void *key) { - union bpf_attr attr; - - memset(&attr, 0, sizeof(attr)); + union bpf_attr attr = { 0 }; attr.map_fd = mapfd; attr.key = (uintptr_t)key; diff --git a/src/util/virdevmapper.c b/src/util/virdevmapper.c index 33cf3e202b..70ce0f0c23 100644 --- a/src/util/virdevmapper.c +++ b/src/util/virdevmapper.c @@ -128,12 +128,10 @@ static int virDMOpen(void) { VIR_AUTOCLOSE controlFD = -1; - struct dm_ioctl dm; + struct dm_ioctl dm = { 0 }; g_autofree char *tmp = NULL; int ret; - memset(&dm, 0, sizeof(dm)); - if ((controlFD = open(CONTROL_PATH, O_RDWR)) < 0) { /* We can't talk to devmapper. Produce a warning and let * the caller decide what to do next. */ @@ -223,12 +221,10 @@ virDevMapperGetTargetsImpl(int controlFD, { g_autofree char *sanitizedPath = NULL; g_autofree char *buf = NULL; - struct dm_ioctl dm; + struct dm_ioctl dm = { 0 }; struct dm_target_deps *deps = NULL; size_t i; - memset(&dm, 0, sizeof(dm)); - if (ttl == 0) { errno = ELOOP; return -1; diff --git a/src/util/virfdstream.c b/src/util/virfdstream.c index 0e39889ac9..26a1f00316 100644 --- a/src/util/virfdstream.c +++ b/src/util/virfdstream.c @@ -1192,7 +1192,7 @@ int virFDStreamConnectUNIX(virStreamPtr st, const char *path, bool abstract) { - struct sockaddr_un sa; + struct sockaddr_un sa = { 0 }; virTimeBackOffVar timeout; VIR_AUTOCLOSE fd = -1; int ret; @@ -1203,7 +1203,6 @@ int virFDStreamConnectUNIX(virStreamPtr st, return -1; } - memset(&sa, 0, sizeof(sa)); sa.sun_family = AF_UNIX; if (abstract) { if (virStrcpy(sa.sun_path+1, path, sizeof(sa.sun_path)-1) < 0) diff --git a/src/util/virfile.c b/src/util/virfile.c index 2984e2ead2..fe456596ae 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -876,14 +876,13 @@ int virFileLoopDeviceAssociate(const char *file, { int lofd = -1; int fsfd = -1; - struct loop_info64 lo; + struct loop_info64 lo = { 0 }; g_autofree char *loname = NULL; int ret = -1; if ((lofd = virFileLoopDeviceOpen(&loname)) < 0) return -1; - memset(&lo, 0, sizeof(lo)); lo.lo_flags = LO_FLAGS_AUTOCLEAR; /* Set backing file name for LOOP_GET_STATUS64 queries */ diff --git a/src/util/virinitctl.c b/src/util/virinitctl.c index 430f23a235..d26249a3e9 100644 --- a/src/util/virinitctl.c +++ b/src/util/virinitctl.c @@ -124,14 +124,12 @@ int virInitctlSetRunLevel(const char *fifo, virInitctlRunLevel level) { - struct virInitctlRequest req; + struct virInitctlRequest req = { 0 }; int fd = -1; int ret = -1; const int open_flags = O_WRONLY|O_NONBLOCK|O_CLOEXEC|O_NOCTTY; size_t i = 0; - memset(&req, 0, sizeof(req)); - req.magic = VIR_INITCTL_MAGIC; req.sleeptime = 0; req.cmd = VIR_INITCTL_CMD_RUNLVL; diff --git a/src/util/viriscsi.c b/src/util/viriscsi.c index 4790bd4b55..a70c87cbdb 100644 --- a/src/util/viriscsi.c +++ b/src/util/viriscsi.c @@ -394,7 +394,7 @@ virISCSIScanTargetsInternal(const char *portal, "^\\s*(\\S+)\\s+(\\S+)\\s*$" }; int vars[] = { 2 }; - struct virISCSITargetList list; + struct virISCSITargetList list = { 0 }; size_t i; g_autoptr(virCommand) cmd = virCommandNewArgList(ISCSIADM, "--mode", "discovery", @@ -414,8 +414,6 @@ virISCSIScanTargetsInternal(const char *portal, NULL); } - memset(&list, 0, sizeof(list)); - if (virCommandRunRegex(cmd, 1, regexes, diff --git a/src/util/virlog.c b/src/util/virlog.c index 6bbd69fe43..2d262d94f0 100644 --- a/src/util/virlog.c +++ b/src/util/virlog.c @@ -897,12 +897,12 @@ virLogOutputToJournald(virLogSource *source, { int buffd = -1; int journalfd = (intptr_t) data; - struct msghdr mh; - struct sockaddr_un sa; + struct msghdr mh = { 0 }; + struct sockaddr_un sa = { 0 }; union { struct cmsghdr cmsghdr; uint8_t buf[CMSG_SPACE(sizeof(int))]; - } control; + } control = { 0 }; struct cmsghdr *cmsg; /* We use /dev/shm instead of /tmp here, since we want this to * be a tmpfs, and one that is available from early boot on @@ -950,12 +950,10 @@ virLogOutputToJournald(virLogSource *source, } } - memset(&sa, 0, sizeof(sa)); sa.sun_family = AF_UNIX; if (virStrcpyStatic(sa.sun_path, "/run/systemd/journal/socket") < 0) return; - memset(&mh, 0, sizeof(mh)); mh.msg_name = &sa; mh.msg_namelen = offsetof(struct sockaddr_un, sun_path) + strlen(sa.sun_path); mh.msg_iov = iov; @@ -983,7 +981,6 @@ virLogOutputToJournald(virLogSource *source, mh.msg_iov = NULL; mh.msg_iovlen = 0; - memset(&control, 0, sizeof(control)); mh.msg_control = &control; mh.msg_controllen = sizeof(control); diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c index 38a4f480eb..46d90fbd76 100644 --- a/src/util/virnetdev.c +++ b/src/util/virnetdev.c @@ -812,9 +812,7 @@ virNetDevGetRcvAllMulti(const char *ifname, #if defined(WITH_IF_INDEXTONAME) char *virNetDevGetName(int ifindex) { - char name[IFNAMSIZ]; - - memset(&name, 0, sizeof(name)); + char name[IFNAMSIZ] = { 0 }; if (!if_indextoname(ifindex, name)) { virReportSystemError(errno, @@ -847,7 +845,7 @@ char *virNetDevGetName(int ifindex) #if defined(SIOCGIFINDEX) && defined(WITH_STRUCT_IFREQ) int virNetDevGetIndex(const char *ifname, int *ifindex) { - struct ifreq ifreq; + struct ifreq ifreq = { 0 }; VIR_AUTOCLOSE fd = socket(VIR_NETDEV_FAMILY, SOCK_DGRAM, 0); if (fd < 0) { @@ -856,8 +854,6 @@ int virNetDevGetIndex(const char *ifname, int *ifindex) return -1; } - memset(&ifreq, 0, sizeof(ifreq)); - if (virStrcpyStatic(ifreq.ifr_name, ifname) < 0) { virReportSystemError(ERANGE, _("invalid interface name %1$s"), diff --git a/src/util/virnetdevbridge.c b/src/util/virnetdevbridge.c index b870e26e5f..5fd88f3195 100644 --- a/src/util/virnetdevbridge.c +++ b/src/util/virnetdevbridge.c @@ -57,11 +57,9 @@ static int virNetDevBridgeCmd(const char *brname, void *arg, size_t argsize) { - struct ifdrv ifd; + struct ifdrv ifd = { 0 }; VIR_AUTOCLOSE s = -1; - memset(&ifd, 0, sizeof(ifd)); - if ((s = socket(AF_LOCAL, SOCK_DGRAM, 0)) < 0) { virReportSystemError(errno, "%s", _("Cannot open network interface control socket")); @@ -621,9 +619,8 @@ int virNetDevBridgeAddPort(const char *brname, int virNetDevBridgeAddPort(const char *brname, const char *ifname) { - struct ifbreq req; + struct ifbreq req = { 0 }; - memset(&req, 0, sizeof(req)); if (virStrcpyStatic(req.ifbr_ifsname, ifname) < 0) { virReportSystemError(ERANGE, _("Network interface name '%1$s' is too long"), @@ -687,9 +684,8 @@ int virNetDevBridgeRemovePort(const char *brname, int virNetDevBridgeRemovePort(const char *brname, const char *ifname) { - struct ifbreq req; + struct ifbreq req = { 0 }; - memset(&req, 0, sizeof(req)); if (virStrcpyStatic(req.ifbr_ifsname, ifname) < 0) { virReportSystemError(ERANGE, _("Network interface name '%1$s' is too long"), diff --git a/src/util/virnetdevip.c b/src/util/virnetdevip.c index d1e717641c..3b02fe0cec 100644 --- a/src/util/virnetdevip.c +++ b/src/util/virnetdevip.c @@ -84,7 +84,7 @@ virNetDevCreateNetlinkAddressMessage(int messageType, virSocketAddr *peer) { struct nl_msg *nlmsg = NULL; - struct ifaddrmsg ifa; + struct ifaddrmsg ifa = { 0 }; unsigned int ifindex; void *addrData = NULL; void *peerData = NULL; @@ -110,8 +110,6 @@ virNetDevCreateNetlinkAddressMessage(int messageType, nlmsg = virNetlinkMsgNew(messageType, NLM_F_REQUEST | NLM_F_CREATE | NLM_F_EXCL); - memset(&ifa, 0, sizeof(ifa)); - ifa.ifa_prefixlen = prefix; ifa.ifa_family = VIR_SOCKET_ADDR_FAMILY(addr); ifa.ifa_index = ifindex; @@ -277,7 +275,7 @@ virNetDevIPRouteAdd(const char *ifname, { unsigned int recvbuflen; unsigned int ifindex; - struct rtmsg rtmsg; + struct rtmsg rtmsg = { 0 }; void *gatewayData = NULL; void *addrData = NULL; size_t addrDataLen; @@ -323,8 +321,6 @@ virNetDevIPRouteAdd(const char *ifname, nlmsg = virNetlinkMsgNew(RTM_NEWROUTE, NLM_F_REQUEST | NLM_F_CREATE | NLM_F_EXCL); - memset(&rtmsg, 0, sizeof(rtmsg)); - rtmsg.rtm_family = VIR_SOCKET_ADDR_FAMILY(gateway); rtmsg.rtm_table = RT_TABLE_MAIN; rtmsg.rtm_scope = RT_SCOPE_UNIVERSE; diff --git a/src/util/virnetdevtap.c b/src/util/virnetdevtap.c index 3e25f18770..3bfd36fc23 100644 --- a/src/util/virnetdevtap.c +++ b/src/util/virnetdevtap.c @@ -270,7 +270,7 @@ int virNetDevTapCreate(char **ifname, int virNetDevTapDelete(const char *ifname, const char *tunpath) { - struct ifreq try; + struct ifreq try = { 0 }; int fd; int ret = -1; @@ -284,7 +284,6 @@ int virNetDevTapDelete(const char *ifname, return -1; } - memset(&try, 0, sizeof(struct ifreq)); try.ifr_flags = IFF_TAP|IFF_NO_PI; if (virStrcpyStatic(try.ifr_name, ifname) < 0) { diff --git a/src/util/virperf.c b/src/util/virperf.c index 03341e73e3..91f2ca632a 100644 --- a/src/util/virperf.c +++ b/src/util/virperf.c @@ -203,7 +203,7 @@ virPerfEventEnable(virPerf *perf, virPerfEventType type, pid_t pid) { - struct perf_event_attr attr; + struct perf_event_attr attr = { 0 }; struct virPerfEvent *event = &(perf->events[type]); struct virPerfEventAttr *event_attr = &attrs[type]; @@ -233,7 +233,6 @@ virPerfEventEnable(virPerf *perf, } } - memset(&attr, 0, sizeof(attr)); attr.size = sizeof(attr); attr.inherit = 1; attr.disabled = 1; diff --git a/src/util/virprocess.c b/src/util/virprocess.c index a26683f333..f8daa786c9 100644 --- a/src/util/virprocess.c +++ b/src/util/virprocess.c @@ -1539,13 +1539,12 @@ virProcessExitWithStatus(int status) if (WIFEXITED(status)) { value = WEXITSTATUS(status); } else if (WIFSIGNALED(status)) { - struct sigaction act; + struct sigaction act = { 0 }; sigset_t sigs; if (sigemptyset(&sigs) == 0 && sigaddset(&sigs, WTERMSIG(status)) == 0) sigprocmask(SIG_UNBLOCK, &sigs, NULL); - memset(&act, 0, sizeof(act)); act.sa_handler = SIG_DFL; sigfillset(&act.sa_mask); sigaction(WTERMSIG(status), &act, NULL); diff --git a/src/util/virsocket.c b/src/util/virsocket.c index a6f185114d..cd6f7ecd1b 100644 --- a/src/util/virsocket.c +++ b/src/util/virsocket.c @@ -389,12 +389,11 @@ virSocketSendFD(int sock, int fd) { char byte = 0; struct iovec iov; - struct msghdr msg; + struct msghdr msg = { 0 }; struct cmsghdr *cmsg; char buf[CMSG_SPACE(sizeof(fd))]; /* send at least one char */ - memset(&msg, 0, sizeof(msg)); iov.iov_base = &byte; iov.iov_len = 1; msg.msg_iov = &iov; @@ -428,7 +427,7 @@ virSocketRecvFD(int sock, int fdflags) { char byte = 0; struct iovec iov; - struct msghdr msg; + struct msghdr msg = { 0 }; int fd = -1; ssize_t len; struct cmsghdr *cmsg; @@ -441,7 +440,6 @@ virSocketRecvFD(int sock, int fdflags) } /* send at least one char */ - memset(&msg, 0, sizeof(msg)); iov.iov_base = &byte; iov.iov_len = 1; msg.msg_iov = &iov; diff --git a/src/util/virsocketaddr.c b/src/util/virsocketaddr.c index 43511bdd69..fbda858cfe 100644 --- a/src/util/virsocketaddr.c +++ b/src/util/virsocketaddr.c @@ -92,7 +92,7 @@ virSocketAddrParseInternal(struct addrinfo **res, int ai_flags, bool reportError) { - struct addrinfo hints; + struct addrinfo hints = { 0 }; int err; if (val == NULL) { @@ -101,7 +101,6 @@ virSocketAddrParseInternal(struct addrinfo **res, return -1; } - memset(&hints, 0, sizeof(hints)); hints.ai_family = family; hints.ai_flags = ai_flags; if ((err = getaddrinfo(val, NULL, &hints, res)) != 0) { @@ -240,12 +239,10 @@ virSocketAddrParseIPv6(virSocketAddr *addr, const char *val) int virSocketAddrResolveService(const char *service) { struct addrinfo *res, *tmp; - struct addrinfo hints; + struct addrinfo hints = { 0 }; int err; int port = -1; - memset(&hints, 0, sizeof(hints)); - if ((err = getaddrinfo(NULL, service, &hints, &res)) != 0) { virReportError(VIR_ERR_SYSTEM_ERROR, _("Cannot parse socket service '%1$s': %2$s"), diff --git a/src/util/viruri.c b/src/util/viruri.c index a824a983df..64995da342 100644 --- a/src/util/viruri.c +++ b/src/util/viruri.c @@ -201,12 +201,10 @@ virURIParse(const char *uri) char * virURIFormat(virURI *uri) { - xmlURI xmluri; + xmlURI xmluri = { 0 }; g_autofree char *tmpserver = NULL; char *ret; - memset(&xmluri, 0, sizeof(xmluri)); - xmluri.scheme = uri->scheme; xmluri.server = uri->server; xmluri.port = uri->port; diff --git a/src/vbox/vbox_storage.c b/src/vbox/vbox_storage.c index 41b19a9c62..2285beea79 100644 --- a/src/vbox/vbox_storage.c +++ b/src/vbox/vbox_storage.c @@ -396,7 +396,7 @@ vboxStorageVolCreateXML(virStoragePoolPtr pool, struct _vboxDriver *data = pool->conn->privateData; PRUnichar *hddFormatUtf16 = NULL; PRUnichar *hddNameUtf16 = NULL; - virStoragePoolDef poolDef; + virStoragePoolDef poolDef = { 0 }; nsresult rc; vboxIID hddIID; unsigned char uuid[VIR_UUID_BUFLEN]; @@ -424,7 +424,6 @@ vboxStorageVolCreateXML(virStoragePoolPtr pool, * so just assign it for now, change the behaviour * when vbox supports pools. */ - memset(&poolDef, 0, sizeof(poolDef)); poolDef.type = VIR_STORAGE_POOL_DIR; if ((def = virStorageVolDefParse(&poolDef, xml, NULL, parseFlags)) == NULL) @@ -720,8 +719,8 @@ static char *vboxStorageVolGetXMLDesc(virStorageVolPtr vol, unsigned int flags) char *hddFormatUtf8 = NULL; PRUint64 hddLogicalSize = 0; PRUint64 hddActualSize = 0; - virStoragePoolDef pool; - virStorageVolDef def; + virStoragePoolDef pool = { 0 }; + virStorageVolDef def = { 0 }; vboxIID hddIID; PRUint32 hddstate; nsresult rc; @@ -732,9 +731,6 @@ static char *vboxStorageVolGetXMLDesc(virStorageVolPtr vol, unsigned int flags) virCheckFlags(0, NULL); - memset(&pool, 0, sizeof(pool)); - memset(&def, 0, sizeof(def)); - if (virUUIDParse(vol->key, uuid) < 0) { virReportError(VIR_ERR_INVALID_ARG, _("Could not parse UUID from '%1$s'"), vol->key); diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c index 5e0f1b6b3e..fe4f253e9e 100644 --- a/src/vmx/vmx.c +++ b/src/vmx/vmx.c @@ -1044,11 +1044,9 @@ virVMXVerifyDiskAddress(virDomainXMLOption *xmlopt, virDomainDiskDef *disk, virDomainDef *vmdef) { - virDomainDiskDef def; + virDomainDiskDef def = { 0 }; virDomainDeviceDriveAddress *drive; - memset(&def, 0, sizeof(def)); - if (disk->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Unsupported disk address type '%1$s'"), diff --git a/tests/nsstest.c b/tests/nsstest.c index 615b063118..4b7895db7e 100644 --- a/tests/nsstest.c +++ b/tests/nsstest.c @@ -39,14 +39,12 @@ testGetHostByName(const void *opaque) { const struct testNSSData *data = opaque; const bool existent = data->hostname && data->ipAddr && data->ipAddr[0]; - struct hostent resolved; + struct hostent resolved = { 0 }; char buf[BUF_SIZE] = { 0 }; char **addrList; int rv, tmp_errno = 0, tmp_herrno = 0; size_t i = 0; - memset(&resolved, 0, sizeof(resolved)); - rv = NSS_NAME(gethostbyname2)(data->hostname, data->af, &resolved, @@ -116,12 +114,10 @@ testGetHostByName(const void *opaque) addrList = resolved.h_addr_list; i = 0; while (*addrList) { - virSocketAddr sa; + virSocketAddr sa = { 0 }; g_autofree char *ipAddr = NULL; void *address = *addrList; - memset(&sa, 0, sizeof(sa)); - if (resolved.h_addrtype == AF_INET) { virSocketAddrSetIPv4AddrNetOrder(&sa, *((uint32_t *) address)); } else { diff --git a/tests/nwfilterxml2firewalltest.c b/tests/nwfilterxml2firewalltest.c index bd112cef83..b78b1b7947 100644 --- a/tests/nwfilterxml2firewalltest.c +++ b/tests/nwfilterxml2firewalltest.c @@ -348,12 +348,10 @@ static int testCompareXMLToArgvFiles(const char *xml, g_autofree char *actualargv = NULL; g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER; g_autoptr(GHashTable) vars = virHashNew(virNWFilterVarValueHashFree); - virNWFilterInst inst; + virNWFilterInst inst = { 0 }; int ret = -1; g_autoptr(virCommandDryRunToken) dryRunToken = virCommandDryRunTokenNew(); - memset(&inst, 0, sizeof(inst)); - virCommandSetDryRun(dryRunToken, &buf, true, true, NULL, NULL); if (testSetDefaultParameters(vars) < 0) diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c index 4672b0a8ff..a1740d3f45 100644 --- a/tests/qemumonitorjsontest.c +++ b/tests/qemumonitorjsontest.c @@ -895,7 +895,7 @@ testQemuMonitorJSONGetObjectProperty(const void *opaque) { const testGenericData *data = opaque; virDomainXMLOption *xmlopt = data->xmlopt; - qemuMonitorJSONObjectProperty prop; + qemuMonitorJSONObjectProperty prop = { 0 }; g_autoptr(qemuMonitorTest) test = NULL; if (!(test = qemuMonitorTestNewSchema(xmlopt, data->schema))) @@ -906,7 +906,6 @@ testQemuMonitorJSONGetObjectProperty(const void *opaque) return -1; /* Present with path and property */ - memset(&prop, 0, sizeof(qemuMonitorJSONObjectProperty)); prop.type = QEMU_MONITOR_OBJECT_PROPERTY_BOOLEAN; if (qemuMonitorJSONGetObjectProperty(qemuMonitorTestGetMonitor(test), "/machine/i440fx", @@ -935,7 +934,7 @@ testQemuMonitorJSONSetObjectProperty(const void *opaque) { const testGenericData *data = opaque; virDomainXMLOption *xmlopt = data->xmlopt; - qemuMonitorJSONObjectProperty prop; + qemuMonitorJSONObjectProperty prop = { 0 }; g_autoptr(qemuMonitorTest) test = NULL; if (!(test = qemuMonitorTestNewSchema(xmlopt, data->schema))) @@ -949,7 +948,6 @@ testQemuMonitorJSONSetObjectProperty(const void *opaque) return -1; /* Let's attempt the setting */ - memset(&prop, 0, sizeof(qemuMonitorJSONObjectProperty)); prop.type = QEMU_MONITOR_OBJECT_PROPERTY_BOOLEAN; prop.val.b = true; if (qemuMonitorJSONSetObjectProperty(qemuMonitorTestGetMonitor(test), diff --git a/tests/qemumonitortestutils.c b/tests/qemumonitortestutils.c index 8b8b02a790..16a4096c98 100644 --- a/tests/qemumonitortestutils.c +++ b/tests/qemumonitortestutils.c @@ -874,9 +874,7 @@ qemuMonitorTestNew(virDomainXMLOption *xmlopt, GHashTable *schema) { g_autoptr(qemuMonitorTest) test = NULL; - virDomainChrSourceDef src; - - memset(&src, 0, sizeof(src)); + virDomainChrSourceDef src = { 0 }; if (!(test = qemuMonitorCommonTestNew(xmlopt, vm, &src))) goto error; @@ -1185,9 +1183,7 @@ qemuMonitorTest * qemuMonitorTestNewAgent(virDomainXMLOption *xmlopt) { g_autoptr(qemuMonitorTest) test = NULL; - virDomainChrSourceDef src; - - memset(&src, 0, sizeof(src)); + virDomainChrSourceDef src = { 0 }; if (!(test = qemuMonitorCommonTestNew(xmlopt, NULL, &src))) goto error; diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 534eb9e699..c44b9bc494 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -546,7 +546,7 @@ testCompareXMLToArgv(const void *data) unsigned int parseFlags = info->parseFlags; int ret = -1; virDomainObj *vm = NULL; - virDomainChrSourceDef monitor_chr; + virDomainChrSourceDef monitor_chr = { 0 }; g_autoptr(virConnect) conn = NULL; virError *err = NULL; g_autofree char *log = NULL; @@ -558,8 +558,6 @@ testCompareXMLToArgv(const void *data) virArch arch = VIR_ARCH_NONE; g_autoptr(virIdentity) sysident = virIdentityGetSystem(); - memset(&monitor_chr, 0, sizeof(monitor_chr)); - if (testQemuInfoInitArgs((struct testQemuInfo *) info) < 0) goto cleanup; diff --git a/tests/virhostcputest.c b/tests/virhostcputest.c index 196f4c29b9..0990013878 100644 --- a/tests/virhostcputest.c +++ b/tests/virhostcputest.c @@ -30,7 +30,7 @@ linuxTestCompareFiles(const char *cpuinfofile, const char *outputfile) { g_autofree char *actualData = NULL; - virNodeInfo nodeinfo; + virNodeInfo nodeinfo = { 0 }; g_autoptr(FILE) cpuinfo = NULL; cpuinfo = fopen(cpuinfofile, "r"); @@ -40,7 +40,6 @@ linuxTestCompareFiles(const char *cpuinfofile, return -1; } - memset(&nodeinfo, 0, sizeof(nodeinfo)); if (virHostCPUGetInfoPopulateLinux(cpuinfo, arch, &nodeinfo.cpus, &nodeinfo.mhz, &nodeinfo.nodes, &nodeinfo.sockets, diff --git a/tests/virnetmessagetest.c b/tests/virnetmessagetest.c index 14790c0ece..e426bc7791 100644 --- a/tests/virnetmessagetest.c +++ b/tests/virnetmessagetest.c @@ -179,7 +179,7 @@ static int testMessageHeaderDecode(const void *args G_GNUC_UNUSED) static int testMessagePayloadEncode(const void *args G_GNUC_UNUSED) { - virNetMessageError err; + virNetMessageError err = { 0 }; virNetMessage *msg = virNetMessageNew(true); int ret = -1; static const char expect[] = { @@ -218,8 +218,6 @@ static int testMessagePayloadEncode(const void *args G_GNUC_UNUSED) if (!msg) return -1; - memset(&err, 0, sizeof(err)); - err.code = VIR_ERR_INTERNAL_ERROR; err.domain = VIR_FROM_RPC; err.level = VIR_ERR_ERROR; @@ -287,7 +285,7 @@ static int testMessagePayloadEncode(const void *args G_GNUC_UNUSED) static int testMessagePayloadDecode(const void *args G_GNUC_UNUSED) { - virNetMessageError err; + virNetMessageError err = { 0 }; virNetMessage *msg = virNetMessageNew(true); static char input_buffer[] = { 0x00, 0x00, 0x00, 0x74, /* Length */ @@ -323,8 +321,6 @@ static int testMessagePayloadDecode(const void *args G_GNUC_UNUSED) }; int ret = -1; - memset(&err, 0, sizeof(err)); - if (!msg) return -1; diff --git a/tools/nss/libvirt_nss.c b/tools/nss/libvirt_nss.c index ec7763224b..ec14ac804b 100644 --- a/tools/nss/libvirt_nss.c +++ b/tools/nss/libvirt_nss.c @@ -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, diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index c74fc19347..89fdc7a050 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -1210,7 +1210,7 @@ cmdDominfo(vshControl *ctl, const vshCmd *cmd) { virDomainInfo info; g_autoptr(virshDomain) dom = NULL; - virSecurityModel secmodel; + virSecurityModel secmodel = { 0 }; int persistent = 0; bool ret = true; int autostart; @@ -1288,7 +1288,6 @@ cmdDominfo(vshControl *ctl, const vshCmd *cmd) has_managed_save ? _("yes") : _("no")); /* Security model and label information */ - memset(&secmodel, 0, sizeof(secmodel)); if (virNodeGetSecurityModel(priv->conn, &secmodel) == -1) { if (last_error->code != VIR_ERR_NO_SUPPORT) { return false; diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index fb54562eb6..7d76055eda 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -6182,7 +6182,7 @@ virshDomainJobStatsToDomainJobInfo(virTypedParameterPtr params, static bool cmdDomjobinfo(vshControl *ctl, const vshCmd *cmd) { - virDomainJobInfo info; + virDomainJobInfo info = { 0 }; g_autoptr(virshDomain) dom = NULL; bool ret = false; const char *unit; @@ -6209,8 +6209,6 @@ cmdDomjobinfo(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptBool(cmd, "keep-completed")) flags |= VIR_DOMAIN_JOB_STATS_KEEP_COMPLETED; - memset(&info, 0, sizeof(info)); - rc = virDomainGetJobStats(dom, &info.type, ¶ms, &nparams, flags); if (rc == 0) { if (virshDomainJobStatsToDomainJobInfo(params, nparams, &info) < 0) diff --git a/tools/vsh-table.c b/tools/vsh-table.c index 005cc564dd..da7dc84ee8 100644 --- a/tools/vsh-table.c +++ b/tools/vsh-table.c @@ -204,9 +204,7 @@ vshTableSafeEncode(const char *s, size_t *width) size_t sz = s ? strlen(s) : 0; char *buf; char *ret; - mbstate_t st; - - memset(&st, 0, sizeof(st)); + mbstate_t st = { 0 }; buf = g_new0(char, (sz * HEX_ENCODE_LENGTH) + 1); -- 2.41.0

On 8/3/23 12:36, Michal Privoznik wrote:
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>
--- src/ch/ch_monitor.c | 3 +- src/conf/domain_conf.c | 8 +- src/conf/network_conf.c | 28 ++---- src/cpu/cpu_x86.c | 4 +- src/esx/esx_driver.c | 20 ++--- src/esx/esx_interface_driver.c | 13 +-- src/esx/esx_storage_backend_iscsi.c | 11 +-- src/esx/esx_storage_backend_vmfs.c | 19 ++-- src/esx/esx_util.c | 4 +- src/libxl/libxl_driver.c | 9 +- src/locking/lock_driver_lockd.c | 19 ++-- src/logging/log_manager.c | 25 ++---- src/lxc/lxc_controller.c | 6 +- src/lxc/lxc_domain.c | 4 +- src/lxc/lxc_driver.c | 4 +- src/nwfilter/nwfilter_dhcpsnoop.c | 4 +- src/nwfilter/nwfilter_gentech_driver.c | 4 +- src/qemu/qemu_agent.c | 10 +-- src/qemu/qemu_command.c | 3 +- src/qemu/qemu_driver.c | 7 +- src/qemu/qemu_monitor.c | 6 +- src/qemu/qemu_monitor_json.c | 7 +- src/qemu/qemu_process.c | 3 +- src/remote/remote_daemon_dispatch.c | 115 ++++++++----------------- src/remote/remote_daemon_stream.c | 23 ++--- src/remote/remote_driver.c | 13 +-- src/rpc/virnetclientprogram.c | 4 +- src/rpc/virnetclientstream.c | 9 +- src/rpc/virnetdaemon.c | 3 +- src/rpc/virnetsaslcontext.c | 3 +- src/rpc/virnetserverprogram.c | 14 +-- src/rpc/virnetsocket.c | 49 +++-------- src/rpc/virnetsshsession.c | 3 +- src/storage/storage_backend_logical.c | 10 +-- src/util/virarptable.c | 3 +- src/util/virauth.c | 4 +- src/util/virbpf.c | 52 +++-------- src/util/virdevmapper.c | 8 +- src/util/virfdstream.c | 3 +- src/util/virfile.c | 3 +- src/util/virinitctl.c | 4 +- src/util/viriscsi.c | 4 +- src/util/virlog.c | 9 +- src/util/virnetdev.c | 8 +- src/util/virnetdevbridge.c | 10 +-- src/util/virnetdevip.c | 8 +- src/util/virnetdevtap.c | 3 +- src/util/virperf.c | 3 +- src/util/virprocess.c | 3 +- src/util/virsocket.c | 6 +- src/util/virsocketaddr.c | 7 +- src/util/viruri.c | 4 +- src/vbox/vbox_storage.c | 10 +-- src/vmx/vmx.c | 4 +- tests/nsstest.c | 8 +- tests/nwfilterxml2firewalltest.c | 4 +- tests/qemumonitorjsontest.c | 6 +- tests/qemumonitortestutils.c | 8 +- tests/qemuxml2argvtest.c | 4 +- tests/virhostcputest.c | 3 +- tests/virnetmessagetest.c | 8 +- tools/nss/libvirt_nss.c | 3 +- tools/virsh-domain-monitor.c | 3 +- tools/virsh-domain.c | 4 +- tools/vsh-table.c | 4 +- 65 files changed, 195 insertions(+), 483 deletions(-)
diff --git a/src/ch/ch_monitor.c b/src/ch/ch_monitor.c index d902bc6959..a4b921931b 100644 --- a/src/ch/ch_monitor.c +++ b/src/ch/ch_monitor.c @@ -468,7 +468,7 @@ virCHMonitorBuildVMJson(virDomainDef *vmdef, static int chMonitorCreateSocket(const char *socket_path) { - struct sockaddr_un addr; + struct sockaddr_un addr = { 0 }; socklen_t addrlen = sizeof(addr); int fd;
@@ -478,7 +478,6 @@ chMonitorCreateSocket(const char *socket_path) goto error; }
- memset(&addr, 0, sizeof(addr)); addr.sun_family = AF_UNIX; if (virStrcpyStatic(addr.sun_path, socket_path) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 5ac5c0b771..47693a49bf 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -28859,9 +28859,7 @@ int virDomainGraphicsListenAppendAddress(virDomainGraphicsDef *def, const char *address) { - virDomainGraphicsListenDef glisten; - - memset(&glisten, 0, sizeof(glisten)); + virDomainGraphicsListenDef glisten = { 0 };
glisten.type = VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS;
@@ -28877,9 +28875,7 @@ int virDomainGraphicsListenAppendSocket(virDomainGraphicsDef *def, const char *socketPath) { - virDomainGraphicsListenDef glisten; - - memset(&glisten, 0, sizeof(glisten)); + virDomainGraphicsListenDef glisten = { 0 };
glisten.type = VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_SOCKET;
diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index 73788b6d87..3e137cb562 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -2748,11 +2748,9 @@ virNetworkDefUpdateIPDHCPHost(virNetworkDef *def, size_t i; int ret = -1; virNetworkIPDef *ipdef = virNetworkIPDefByIndex(def, parentIndex); - virNetworkDHCPHostDef host; + virNetworkDHCPHostDef host = { 0 }; bool partialOkay = (command == VIR_NETWORK_UPDATE_COMMAND_DELETE);
- memset(&host, 0, sizeof(host)); - if (virNetworkDefUpdateCheckElementName(def, ctxt->node, "host") < 0) goto cleanup;
@@ -2881,9 +2879,7 @@ virNetworkDefUpdateIPDHCPRange(virNetworkDef *def, { size_t i; virNetworkIPDef *ipdef = virNetworkIPDefByIndex(def, parentIndex); - virNetworkDHCPRangeDef range; - - memset(&range, 0, sizeof(range)); + virNetworkDHCPRangeDef range = { 0 };
if (virNetworkDefUpdateCheckElementName(def, ctxt->node, "range") < 0) return -1; @@ -2990,9 +2986,7 @@ virNetworkDefUpdateForwardInterface(virNetworkDef *def, { size_t i; int ret = -1; - virNetworkForwardIfDef iface; - - memset(&iface, 0, sizeof(iface)); + virNetworkForwardIfDef iface = { 0 };
if (virNetworkDefUpdateCheckElementName(def, ctxt->node, "interface") < 0) goto cleanup; @@ -3094,9 +3088,7 @@ virNetworkDefUpdatePortGroup(virNetworkDef *def, size_t i; int foundName = -1, foundDefault = -1; int ret = -1; - virPortGroupDef portgroup; - - memset(&portgroup, 0, sizeof(portgroup)); + virPortGroupDef portgroup = { 0 };
if (virNetworkDefUpdateCheckElementName(def, ctxt->node, "portgroup") < 0) goto cleanup; @@ -3184,13 +3176,11 @@ virNetworkDefUpdateDNSHost(virNetworkDef *def, size_t i, j, k; int foundIdx = -1, ret = -1; virNetworkDNSDef *dns = &def->dns; - virNetworkDNSHostDef host; + virNetworkDNSHostDef host = { 0 }; bool isAdd = (command == VIR_NETWORK_UPDATE_COMMAND_ADD_FIRST || command == VIR_NETWORK_UPDATE_COMMAND_ADD_LAST); int foundCt = 0;
- memset(&host, 0, sizeof(host)); - if (command == VIR_NETWORK_UPDATE_COMMAND_MODIFY) { virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", _("DNS HOST records cannot be modified, " @@ -3283,13 +3273,11 @@ virNetworkDefUpdateDNSSrv(virNetworkDef *def, size_t i; int foundIdx = -1, ret = -1; virNetworkDNSDef *dns = &def->dns; - virNetworkDNSSrvDef srv; + virNetworkDNSSrvDef srv = { 0 }; bool isAdd = (command == VIR_NETWORK_UPDATE_COMMAND_ADD_FIRST || command == VIR_NETWORK_UPDATE_COMMAND_ADD_LAST); int foundCt = 0;
- memset(&srv, 0, sizeof(srv)); - if (command == VIR_NETWORK_UPDATE_COMMAND_MODIFY) { virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", _("DNS SRV records cannot be modified, " @@ -3368,12 +3356,10 @@ virNetworkDefUpdateDNSTxt(virNetworkDef *def, { int foundIdx, ret = -1; virNetworkDNSDef *dns = &def->dns; - virNetworkDNSTxtDef txt; + virNetworkDNSTxtDef txt = { 0 }; bool isAdd = (command == VIR_NETWORK_UPDATE_COMMAND_ADD_FIRST || command == VIR_NETWORK_UPDATE_COMMAND_ADD_LAST);
- memset(&txt, 0, sizeof(txt)); - if (command == VIR_NETWORK_UPDATE_COMMAND_MODIFY) { virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", _("DNS TXT records cannot be modified, " diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c index 3c0163c4d1..b9513e24d5 100644 --- a/src/cpu/cpu_x86.c +++ b/src/cpu/cpu_x86.c @@ -1073,9 +1073,7 @@ static int x86ParseMSR(xmlNodePtr node, virCPUx86DataItem *item) { - virCPUx86MSR msr; - - memset(&msr, 0, sizeof(msr)); + virCPUx86MSR msr = { 0 };
if (virXMLPropUInt(node, "index", 0, VIR_XML_PROP_REQUIRED, &msr.index) < 0) return -1; diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c index 0d1b10fe8b..b243bbf411 100644 --- a/src/esx/esx_driver.c +++ b/src/esx/esx_driver.c @@ -2536,14 +2536,12 @@ esxDomainGetXMLDesc(virDomainPtr domain, unsigned int flags) g_autofree char *url = NULL; g_autofree char *vmx = NULL; virVMXContext ctx; - esxVMX_Data data; + esxVMX_Data data = { 0 }; g_autoptr(virDomainDef) def = NULL; char *xml = NULL;
virCheckFlags(VIR_DOMAIN_XML_COMMON_FLAGS, NULL);
- memset(&data, 0, sizeof(data)); - if (esxVI_EnsureSession(priv->primary) < 0) return NULL;
@@ -2622,14 +2620,12 @@ esxConnectDomainXMLFromNative(virConnectPtr conn, const char *nativeFormat, { esxPrivate *priv = conn->privateData; virVMXContext ctx; - esxVMX_Data data; + esxVMX_Data data = { 0 }; g_autoptr(virDomainDef) def = NULL; char *xml = NULL;
virCheckFlags(0, NULL);
- memset(&data, 0, sizeof(data)); - if (STRNEQ(nativeFormat, VMX_CONFIG_FORMAT_ARGV)) { virReportError(VIR_ERR_INVALID_ARG, _("Unsupported config format '%1$s'"), nativeFormat); @@ -2665,14 +2661,12 @@ esxConnectDomainXMLToNative(virConnectPtr conn, const char *nativeFormat, esxPrivate *priv = conn->privateData; int virtualHW_version; virVMXContext ctx; - esxVMX_Data data; + esxVMX_Data data = { 0 }; g_autoptr(virDomainDef) def = NULL; char *vmx = NULL;
virCheckFlags(0, NULL);
- memset(&data, 0, sizeof(data)); - if (STRNEQ(nativeFormat, VMX_CONFIG_FORMAT_ARGV)) { virReportError(VIR_ERR_INVALID_ARG, _("Unsupported config format '%1$s'"), nativeFormat); @@ -2870,7 +2864,7 @@ esxDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags) esxVI_ObjectContent *virtualMachine = NULL; int virtualHW_version; virVMXContext ctx; - esxVMX_Data data; + esxVMX_Data data = { 0 }; g_autofree char *datastoreName = NULL; g_autofree char *directoryName = NULL; g_autofree char *escapedName = NULL; @@ -2892,8 +2886,6 @@ esxDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags) if (flags & VIR_DOMAIN_DEFINE_VALIDATE) parse_flags |= VIR_DOMAIN_DEF_PARSE_VALIDATE_SCHEMA;
- memset(&data, 0, sizeof(data)); - if (esxVI_EnsureSession(priv->primary) < 0) return NULL;
@@ -4058,14 +4050,12 @@ esxDomainSnapshotGetXMLDesc(virDomainSnapshotPtr snapshot, esxVI_VirtualMachineSnapshotTree *rootSnapshotList = NULL; esxVI_VirtualMachineSnapshotTree *snapshotTree = NULL; esxVI_VirtualMachineSnapshotTree *snapshotTreeParent = NULL; - virDomainSnapshotDef def; + virDomainSnapshotDef def = { 0 }; char uuid_string[VIR_UUID_STRING_BUFLEN] = ""; char *xml = NULL;
virCheckFlags(0, NULL);
- memset(&def, 0, sizeof(def)); - if (esxVI_EnsureSession(priv->primary) < 0) return NULL;
diff --git a/src/esx/esx_interface_driver.c b/src/esx/esx_interface_driver.c index d6b6410d1a..125155da99 100644 --- a/src/esx/esx_interface_driver.c +++ b/src/esx/esx_interface_driver.c @@ -157,21 +157,16 @@ esxInterfaceGetXMLDesc(virInterfacePtr iface, unsigned int flags) char *xml = NULL; esxPrivate *priv = iface->conn->privateData; esxVI_PhysicalNic *physicalNic = NULL; - virInterfaceDef def; + virInterfaceDef def = { 0 }; bool hasAddress = false; virInterfaceProtocolDef *protocols; - virInterfaceProtocolDef protocol; - virSocketAddr socketAddress; + virInterfaceProtocolDef protocol = { 0 }; + virSocketAddr socketAddress = { 0 }; virInterfaceIPDef *ips; - virInterfaceIPDef ip; + virInterfaceIPDef ip = { 0 };
virCheckFlags(VIR_INTERFACE_XML_INACTIVE, NULL);
- memset(&def, 0, sizeof(def)); - memset(&protocol, 0, sizeof(protocol)); - memset(&socketAddress, 0, sizeof(socketAddress)); - memset(&ip, 0, sizeof(ip)); - if (esxVI_EnsureSession(priv->primary) < 0 || esxVI_LookupPhysicalNicByMACAddress(priv->primary, iface->mac, &physicalNic, diff --git a/src/esx/esx_storage_backend_iscsi.c b/src/esx/esx_storage_backend_iscsi.c index 087365392b..c00b1e4f32 100644 --- a/src/esx/esx_storage_backend_iscsi.c +++ b/src/esx/esx_storage_backend_iscsi.c @@ -302,12 +302,10 @@ esxStoragePoolGetXMLDesc(virStoragePoolPtr pool, unsigned int flags) esxPrivate *priv = pool->conn->privateData; esxVI_HostInternetScsiHba *hostInternetScsiHba = NULL; esxVI_HostInternetScsiHbaStaticTarget *target; - virStoragePoolDef def; + virStoragePoolDef def = { 0 };
virCheckFlags(0, NULL);
- memset(&def, 0, sizeof(def)); - if (esxVI_LookupHostInternetScsiHba(priv->primary, &hostInternetScsiHba)) goto cleanup;
@@ -664,20 +662,17 @@ esxStorageVolGetXMLDesc(virStorageVolPtr volume, { char *xml = NULL; esxPrivate *priv = volume->conn->privateData; - virStoragePoolDef pool; + virStoragePoolDef pool = { 0 }; esxVI_ScsiLun *scsiLunList = NULL; esxVI_ScsiLun *scsiLun; esxVI_HostScsiDisk *hostScsiDisk = NULL; - virStorageVolDef def; + virStorageVolDef def = { 0 }; /* VIR_CRYPTO_HASH_SIZE_MD5 = VIR_UUID_BUFLEN = 16 */ unsigned char md5[VIR_CRYPTO_HASH_SIZE_MD5]; char uuid_string[VIR_UUID_STRING_BUFLEN] = "";
virCheckFlags(0, NULL);
- memset(&pool, 0, sizeof(pool)); - memset(&def, 0, sizeof(def)); - if (esxVI_LookupScsiLunList(priv->primary, &scsiLunList) < 0) goto cleanup;
diff --git a/src/esx/esx_storage_backend_vmfs.c b/src/esx/esx_storage_backend_vmfs.c index f00c7eec4e..7c5df1c9cd 100644 --- a/src/esx/esx_storage_backend_vmfs.c +++ b/src/esx/esx_storage_backend_vmfs.c @@ -442,15 +442,13 @@ esxStoragePoolGetXMLDesc(virStoragePoolPtr pool, unsigned int flags) esxVI_DatastoreHostMount *hostMount = NULL; esxVI_DynamicProperty *dynamicProperty = NULL; esxVI_Boolean accessible = esxVI_Boolean_Undefined; - virStoragePoolDef def; + virStoragePoolDef def = { 0 }; esxVI_DatastoreInfo *info = NULL; esxVI_NasDatastoreInfo *nasInfo = NULL; char *xml = NULL;
virCheckFlags(0, NULL);
- memset(&def, 0, sizeof(def)); - if (esxVI_String_AppendValueListToList(&propertyNameList, "summary.accessible\0" "summary.capacity\0" @@ -833,7 +831,7 @@ esxStorageVolCreateXML(virStoragePoolPtr pool, { virStorageVolPtr volume = NULL; esxPrivate *priv = pool->conn->privateData; - virStoragePoolDef poolDef; + virStoragePoolDef poolDef = { 0 }; char *tmp; g_autofree char *unescapedDatastorePath = NULL; g_autofree char *unescapedDirectoryName = NULL; @@ -853,8 +851,6 @@ esxStorageVolCreateXML(virStoragePoolPtr pool,
virCheckFlags(0, NULL);
- memset(&poolDef, 0, sizeof(poolDef)); - if (esxLookupVMFSStoragePoolType(priv->primary, pool->name, &poolDef.type) < 0) { goto cleanup; @@ -1032,7 +1028,7 @@ esxStorageVolCreateXMLFrom(virStoragePoolPtr pool, { virStorageVolPtr volume = NULL; esxPrivate *priv = pool->conn->privateData; - virStoragePoolDef poolDef; + virStoragePoolDef poolDef = { 0 }; g_autofree char *sourceDatastorePath = NULL; char *tmp; g_autofree char *unescapedDatastorePath = NULL; @@ -1052,8 +1048,6 @@ esxStorageVolCreateXMLFrom(virStoragePoolPtr pool,
virCheckFlags(0, NULL);
- memset(&poolDef, 0, sizeof(poolDef)); - if (esxLookupVMFSStoragePoolType(priv->primary, pool->name, &poolDef.type) < 0) { goto cleanup; @@ -1312,20 +1306,17 @@ esxStorageVolGetXMLDesc(virStorageVolPtr volume, unsigned int flags) { esxPrivate *priv = volume->conn->privateData; - virStoragePoolDef pool; + virStoragePoolDef pool = { 0 }; g_autofree char *datastorePath = NULL; esxVI_FileInfo *fileInfo = NULL; esxVI_VmDiskFileInfo *vmDiskFileInfo = NULL; esxVI_IsoImageFileInfo *isoImageFileInfo = NULL; esxVI_FloppyImageFileInfo *floppyImageFileInfo = NULL; - virStorageVolDef def; + virStorageVolDef def = { 0 }; char *xml = NULL;
virCheckFlags(0, NULL);
- memset(&pool, 0, sizeof(pool)); - memset(&def, 0, sizeof(def)); - if (esxLookupVMFSStoragePoolType(priv->primary, volume->pool, &pool.type) < 0) { return NULL; diff --git a/src/esx/esx_util.c b/src/esx/esx_util.c index fbbf226555..785701a518 100644 --- a/src/esx/esx_util.c +++ b/src/esx/esx_util.c @@ -272,13 +272,11 @@ esxUtil_ParseDatastorePath(const char *datastorePath, char **datastoreName, int esxUtil_ResolveHostname(const char *hostname, char **ipAddress) { - struct addrinfo hints; + struct addrinfo hints = { 0 }; struct addrinfo *result = NULL; int errcode; g_autofree char *address = NULL;
- memset(&hints, 0, sizeof(hints)); - hints.ai_flags = AI_ADDRCONFIG; hints.ai_family = AF_INET; hints.ai_socktype = SOCK_STREAM; diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index 2644d1400a..3d10f45850 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -1796,7 +1796,7 @@ libxlDoDomainSave(libxlDriverPrivate *driver, bool managed) { libxlDriverConfig *cfg = libxlDriverConfigGet(driver); - libxlSavefileHeader hdr; + libxlSavefileHeader hdr = { 0 }; virObjectEvent *event = NULL; g_autofree char *xml = NULL; uint32_t xml_len; @@ -1821,7 +1821,6 @@ libxlDoDomainSave(libxlDriverPrivate *driver, goto cleanup; xml_len = strlen(xml) + 1;
- memset(&hdr, 0, sizeof(hdr)); memcpy(hdr.magic, LIBXL_SAVE_MAGIC, sizeof(hdr.magic)); hdr.version = LIBXL_SAVE_VERSION; hdr.xmlLen = xml_len; @@ -5651,7 +5650,7 @@ libxlDomainBlockStats(virDomainPtr dom, virDomainBlockStatsPtr stats) { virDomainObj *vm; - libxlBlockStats blkstats; + libxlBlockStats blkstats = { 0 }; int ret = -1;
if (!(vm = libxlDomObjFromDomain(dom))) @@ -5666,7 +5665,6 @@ libxlDomainBlockStats(virDomainPtr dom, if (virDomainObjCheckActive(vm) < 0) goto endjob;
- memset(&blkstats, 0, sizeof(libxlBlockStats)); if ((ret = libxlDomainBlockStatsGather(vm, path, &blkstats)) < 0) goto endjob;
@@ -5695,7 +5693,7 @@ libxlDomainBlockStatsFlags(virDomainPtr dom, unsigned int flags) { virDomainObj *vm; - libxlBlockStats blkstats; + libxlBlockStats blkstats = { 0 }; int nstats; int ret = -1;
@@ -5722,7 +5720,6 @@ libxlDomainBlockStatsFlags(virDomainPtr dom, goto endjob; }
- memset(&blkstats, 0, sizeof(libxlBlockStats)); if ((ret = libxlDomainBlockStatsGather(vm, path, &blkstats)) < 0) goto endjob;
diff --git a/src/locking/lock_driver_lockd.c b/src/locking/lock_driver_lockd.c index 6b294e2954..d75302dd0a 100644 --- a/src/locking/lock_driver_lockd.c +++ b/src/locking/lock_driver_lockd.c @@ -138,9 +138,7 @@ virLockManagerLockDaemonConnectionRegister(virLockManager *lock, int *counter) { virLockManagerLockDaemonPrivate *priv = lock->privateData; - virLockSpaceProtocolRegisterArgs args; - - memset(&args, 0, sizeof(args)); + virLockSpaceProtocolRegisterArgs args = { 0 };
args.flags = 0; memcpy(args.owner.uuid, priv->uuid, VIR_UUID_BUFLEN); @@ -167,9 +165,7 @@ virLockManagerLockDaemonConnectionRestrict(virLockManager *lock G_GNUC_UNUSED, virNetClientProgram *program, int *counter) { - virLockSpaceProtocolRestrictArgs args; - - memset(&args, 0, sizeof(args)); + virLockSpaceProtocolRestrictArgs args = { 0 };
args.flags = 0;
@@ -259,11 +255,10 @@ static int virLockManagerLockDaemonSetupLockspace(const char *path) { virNetClient *client; virNetClientProgram *program = NULL; - virLockSpaceProtocolCreateLockSpaceArgs args; + virLockSpaceProtocolCreateLockSpaceArgs args = { 0 }; int rv = -1; int counter = 0;
- memset(&args, 0, sizeof(args)); args.path = (char*)path;
if (!(client = virLockManagerLockDaemonConnectionNew(geteuid() == 0, &program))) @@ -671,9 +666,7 @@ static int virLockManagerLockDaemonAcquire(virLockManager *lock, if (!(flags & VIR_LOCK_MANAGER_ACQUIRE_REGISTER_ONLY)) { size_t i; for (i = 0; i < priv->nresources; i++) { - virLockSpaceProtocolAcquireResourceArgs args; - - memset(&args, 0, sizeof(args)); + virLockSpaceProtocolAcquireResourceArgs args = { 0 };
args.path = priv->resources[i].lockspace; args.name = priv->resources[i].name; @@ -726,9 +719,7 @@ static int virLockManagerLockDaemonRelease(virLockManager *lock, goto cleanup;
for (i = 0; i < priv->nresources; i++) { - virLockSpaceProtocolReleaseResourceArgs args; - - memset(&args, 0, sizeof(args)); + virLockSpaceProtocolReleaseResourceArgs args = { 0 };
if (priv->resources[i].lockspace) args.path = priv->resources[i].lockspace; diff --git a/src/logging/log_manager.c b/src/logging/log_manager.c index 6e8e7e9f1a..d8490f4e5a 100644 --- a/src/logging/log_manager.c +++ b/src/logging/log_manager.c @@ -149,15 +149,12 @@ virLogManagerDomainOpenLogFile(virLogManager *mgr, ino_t *inode, off_t *offset) { - struct virLogManagerProtocolDomainOpenLogFileArgs args; - struct virLogManagerProtocolDomainOpenLogFileRet ret; + struct virLogManagerProtocolDomainOpenLogFileArgs args = { 0 }; + struct virLogManagerProtocolDomainOpenLogFileRet ret = { 0 }; int *fdout = NULL; size_t fdoutlen = 0; int rv = -1;
- memset(&args, 0, sizeof(args)); - memset(&ret, 0, sizeof(ret)); - args.driver = (char *)driver; memcpy(args.dom.uuid, domuuid, VIR_UUID_BUFLEN); args.dom.name = (char *)domname; @@ -208,11 +205,8 @@ virLogManagerDomainGetLogFilePosition(virLogManager *mgr, ino_t *inode, off_t *offset) { - struct virLogManagerProtocolDomainGetLogFilePositionArgs args; - struct virLogManagerProtocolDomainGetLogFilePositionRet ret; - - memset(&args, 0, sizeof(args)); - memset(&ret, 0, sizeof(ret)); + struct virLogManagerProtocolDomainGetLogFilePositionArgs args = { 0 }; + struct virLogManagerProtocolDomainGetLogFilePositionRet ret = { 0 };
args.path = (char *)path; args.flags = flags; @@ -241,11 +235,8 @@ virLogManagerDomainReadLogFile(virLogManager *mgr, size_t maxlen, unsigned int flags) { - struct virLogManagerProtocolDomainReadLogFileArgs args; - struct virLogManagerProtocolDomainReadLogFileRet ret; - - memset(&args, 0, sizeof(args)); - memset(&ret, 0, sizeof(ret)); + struct virLogManagerProtocolDomainReadLogFileArgs args = { 0 }; + struct virLogManagerProtocolDomainReadLogFileRet ret = { 0 };
args.path = (char *)path; args.flags = flags; @@ -275,11 +266,9 @@ virLogManagerDomainAppendMessage(virLogManager *mgr, const char *message, unsigned int flags) { - struct virLogManagerProtocolDomainAppendLogFileArgs args; + struct virLogManagerProtocolDomainAppendLogFileArgs args = { 0 }; struct virLogManagerProtocolDomainAppendLogFileRet ret;
- memset(&args, 0, sizeof(args)); - args.driver = (char *)driver; memcpy(args.dom.uuid, domuuid, VIR_UUID_BUFLEN); args.dom.name = (char *)domname; diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c index 86dcd880e8..51459b47e7 100644 --- a/src/lxc/lxc_controller.c +++ b/src/lxc/lxc_controller.c @@ -2235,10 +2235,9 @@ static int virLXCControllerEventSendExit(virLXCController *ctrl, int exitstatus) { - virLXCMonitorExitEventMsg msg; + virLXCMonitorExitEventMsg msg = { 0 };
VIR_DEBUG("Exit status %d (client=%p)", exitstatus, ctrl->client); - memset(&msg, 0, sizeof(msg)); switch (exitstatus) { case 0: msg.status = VIR_LXC_MONITOR_EXIT_STATUS_SHUTDOWN; @@ -2272,10 +2271,9 @@ static int virLXCControllerEventSendInit(virLXCController *ctrl, pid_t initpid) { - virLXCMonitorInitEventMsg msg; + virLXCMonitorInitEventMsg msg = { 0 };
VIR_DEBUG("Init pid %lld", (long long)initpid); - memset(&msg, 0, sizeof(msg)); msg.initpid = initpid;
virLXCControllerEventSend(ctrl, diff --git a/src/lxc/lxc_domain.c b/src/lxc/lxc_domain.c index e8c87423bf..cf9bf96a4e 100644 --- a/src/lxc/lxc_domain.c +++ b/src/lxc/lxc_domain.c @@ -339,13 +339,11 @@ virLXCDomainSetRunlevel(virDomainObj *vm, int runlevel) { virLXCDomainObjPrivate *priv = vm->privateData; - lxcDomainInitctlCallbackData data; + lxcDomainInitctlCallbackData data = { 0 }; size_t nfifos = 0; size_t i; int ret = -1;
- memset(&data, 0, sizeof(data)); - data.runlevel = runlevel;
for (nfifos = 0; virInitctlFifos[nfifos]; nfifos++) diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 3bc01cbc23..f284798f1c 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -3327,9 +3327,7 @@ lxcDomainAttachDeviceMknod(virLXCDriver *driver, char *file) { virLXCDomainObjPrivate *priv = vm->privateData; - struct lxcDomainAttachDeviceMknodData data; - - memset(&data, 0, sizeof(data)); + struct lxcDomainAttachDeviceMknodData data = { 0 };
data.driver = driver; data.mode = mode; diff --git a/src/nwfilter/nwfilter_dhcpsnoop.c b/src/nwfilter/nwfilter_dhcpsnoop.c index 3dc0b777e9..2f89923856 100644 --- a/src/nwfilter/nwfilter_dhcpsnoop.c +++ b/src/nwfilter/nwfilter_dhcpsnoop.c @@ -817,7 +817,7 @@ virNWFilterSnoopDHCPDecode(virNWFilterSnoopReq *req, struct iphdr *pip; struct udphdr *pup; virNWFilterSnoopDHCPHdr *pd; - virNWFilterSnoopIPLease ipl; + virNWFilterSnoopIPLease ipl = { 0 }; uint8_t mtype; uint32_t leasetime; uint32_t nwint; @@ -863,8 +863,6 @@ virNWFilterSnoopDHCPDecode(virNWFilterSnoopReq *req, if (virNWFilterSnoopDHCPGetOpt(pd, len, &mtype, &leasetime) < 0) return -2;
- memset(&ipl, 0, sizeof(ipl)); - memcpy(&nwint, &pd->d_yiaddr, sizeof(nwint)); virSocketAddrSetIPv4AddrNetOrder(&ipl.ipAddress, nwint);
diff --git a/src/nwfilter/nwfilter_gentech_driver.c b/src/nwfilter/nwfilter_gentech_driver.c index 72e24e2f08..41f270bb7c 100644 --- a/src/nwfilter/nwfilter_gentech_driver.c +++ b/src/nwfilter/nwfilter_gentech_driver.c @@ -463,7 +463,7 @@ virNWFilterDoInstantiate(virNWFilterTechDriver *techdriver, bool forceWithPendingReq) { int rc; - virNWFilterInst inst; + virNWFilterInst inst = { 0 }; bool instantiate = true; g_autofree char *buf = NULL; virNWFilterVarValue *lv; @@ -471,8 +471,6 @@ virNWFilterDoInstantiate(virNWFilterTechDriver *techdriver, bool reportIP = false; g_autoptr(GHashTable) missing_vars = virHashNew(virNWFilterVarValueHashFree);
- memset(&inst, 0, sizeof(inst)); - rc = virNWFilterDetermineMissingVarsRec(filter, binding->filterparams, missing_vars, diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c index eda1308097..7fc412c17e 100644 --- a/src/qemu/qemu_agent.c +++ b/src/qemu/qemu_agent.c @@ -149,7 +149,7 @@ static void qemuAgentDispose(void *obj) static int qemuAgentOpenUnix(const char *socketpath) { - struct sockaddr_un addr; + struct sockaddr_un addr = { 0 }; int agentfd;
if ((agentfd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) { @@ -165,7 +165,6 @@ qemuAgentOpenUnix(const char *socketpath) goto error; }
- memset(&addr, 0, sizeof(addr)); addr.sun_family = AF_UNIX; if (virStrcpyStatic(addr.sun_path, socketpath) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -803,11 +802,9 @@ qemuAgentGuestSyncSend(qemuAgent *agent, g_autofree char *txMsg = NULL; g_autoptr(virJSONValue) rxObj = NULL; unsigned long long id; - qemuAgentMessage sync_msg; + qemuAgentMessage sync_msg = { 0 }; int rc;
- memset(&sync_msg, 0, sizeof(sync_msg)); - if (virTimeMillisNow(&id) < 0) return -1;
@@ -1015,12 +1012,11 @@ qemuAgentCommandFull(qemuAgent *agent, bool report_unsupported) { int ret = -1; - qemuAgentMessage msg; + qemuAgentMessage msg = { 0 }; g_autofree char *cmdstr = NULL; int await_event = agent->await_event;
*reply = NULL; - memset(&msg, 0, sizeof(msg));
if (!agent->running) { virReportError(VIR_ERR_AGENT_UNRESPONSIVE, "%s", diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 64af0b5ea9..77c5335bde 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -4868,7 +4868,7 @@ qemuBuildSCSIHostdevDevProps(const virDomainDef *def, int qemuOpenChrChardevUNIXSocket(const virDomainChrSourceDef *dev) { - struct sockaddr_un addr; + struct sockaddr_un addr = { 0 }; socklen_t addrlen = sizeof(addr); int fd;
@@ -4878,7 +4878,6 @@ qemuOpenChrChardevUNIXSocket(const virDomainChrSourceDef *dev) goto error; }
- memset(&addr, 0, sizeof(addr)); addr.sun_family = AF_UNIX; if (virStrcpyStatic(addr.sun_path, dev->data.nix.path) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 1f388306f4..f8039160f4 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -14933,8 +14933,8 @@ qemuDomainSetBlockIoTune(virDomainPtr dom, qemuDomainObjPrivate *priv; virDomainDef *def = NULL; virDomainDef *persistentDef = NULL; - virDomainBlockIoTuneInfo info; - virDomainBlockIoTuneInfo conf_info; + virDomainBlockIoTuneInfo info = { 0 }; + virDomainBlockIoTuneInfo conf_info = { 0 }; int ret = -1; size_t i; virDomainDiskDef *conf_disk = NULL; @@ -14995,9 +14995,6 @@ qemuDomainSetBlockIoTune(virDomainPtr dom, NULL) < 0) return -1;
- memset(&info, 0, sizeof(info)); - memset(&conf_info, 0, sizeof(conf_info)); - if (!(vm = qemuDomainObjFromDomain(dom))) return -1;
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index c680c4b804..db34b6c179 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -227,7 +227,7 @@ qemuMonitorDispose(void *obj) static int qemuMonitorOpenUnix(const char *monitor) { - struct sockaddr_un addr; + struct sockaddr_un addr = { 0 }; VIR_AUTOCLOSE monfd = -1; int ret = -1;
@@ -237,7 +237,6 @@ qemuMonitorOpenUnix(const char *monitor) return -1; }
- memset(&addr, 0, sizeof(addr)); addr.sun_family = AF_UNIX; if (virStrcpyStatic(addr.sun_path, monitor) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -309,13 +308,12 @@ qemuMonitorIOWriteWithFD(qemuMonitor *mon, size_t len, int fd) { - struct msghdr msg; + struct msghdr msg = { 0 }; struct iovec iov[1]; int ret; char control[CMSG_SPACE(sizeof(int))]; struct cmsghdr *cmsg;
- memset(&msg, 0, sizeof(msg)); memset(control, 0, sizeof(control));
iov[0].iov_base = (void *)data; diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index d9e9a4481c..70536028ab 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -259,13 +259,11 @@ qemuMonitorJSONCommandWithFd(qemuMonitor *mon, virJSONValue **reply) { int ret = -1; - qemuMonitorMessage msg; + qemuMonitorMessage msg = { 0 }; g_auto(virBuffer) cmdbuf = VIR_BUFFER_INITIALIZER;
*reply = NULL;
- memset(&msg, 0, sizeof(msg)); - if (virJSONValueObjectHasKey(cmd, "execute")) { g_autofree char *id = qemuMonitorNextCommandID(mon);
@@ -2035,10 +2033,9 @@ qemuMonitorJSONSetMemoryStatsPeriod(qemuMonitor *mon, char *balloonpath, int period) { - qemuMonitorJSONObjectProperty prop; + qemuMonitorJSONObjectProperty prop = { 0 };
/* Set to the value in memballoon (could enable or disable) */ - memset(&prop, 0, sizeof(qemuMonitorJSONObjectProperty)); prop.type = QEMU_MONITOR_OBJECT_PROPERTY_INT; prop.val.iv = period; if (qemuMonitorJSONSetObjectProperty(mon, balloonpath, diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index db06991450..572b842349 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -2226,14 +2226,13 @@ qemuRefreshRTC(virDomainObj *vm) { qemuDomainObjPrivate *priv = vm->privateData; time_t now, then; - struct tm thenbits; + struct tm thenbits = { 0 }; long localOffset; int rv;
if (vm->def->clock.offset != VIR_DOMAIN_CLOCK_OFFSET_VARIABLE) return;
- memset(&thenbits, 0, sizeof(thenbits)); qemuDomainObjEnterMonitor(vm); now = time(NULL); rv = qemuMonitorGetRTCTime(priv->mon, &thenbits); diff --git a/src/remote/remote_daemon_dispatch.c b/src/remote/remote_daemon_dispatch.c index 7144e9e7ca..2bb9e306a4 100644 --- a/src/remote/remote_daemon_dispatch.c +++ b/src/remote/remote_daemon_dispatch.c @@ -313,7 +313,7 @@ remoteRelayDomainEventLifecycle(virConnectPtr conn, void *opaque) { daemonClientEventCallback *callback = opaque; - remote_domain_event_lifecycle_msg data; + remote_domain_event_lifecycle_msg data = { 0 };
if (callback->callbackID < 0 || !remoteRelayDomainEventCheckACL(callback->client, conn, dom)) @@ -323,7 +323,6 @@ remoteRelayDomainEventLifecycle(virConnectPtr conn, event, detail, callback->callbackID, callback->legacy);
/* build return data */ - memset(&data, 0, sizeof(data)); make_nonnull_domain(&data.dom, dom); data.event = event; data.detail = detail; @@ -352,7 +351,7 @@ remoteRelayDomainEventReboot(virConnectPtr conn, void *opaque) { daemonClientEventCallback *callback = opaque; - remote_domain_event_reboot_msg data; + remote_domain_event_reboot_msg data = { 0 };
if (callback->callbackID < 0 || !remoteRelayDomainEventCheckACL(callback->client, conn, dom)) @@ -362,7 +361,6 @@ remoteRelayDomainEventReboot(virConnectPtr conn, dom->name, dom->id, callback->callbackID, callback->legacy);
/* build return data */ - memset(&data, 0, sizeof(data)); make_nonnull_domain(&data.dom, dom);
if (callback->legacy) { @@ -389,7 +387,7 @@ remoteRelayDomainEventRTCChange(virConnectPtr conn, void *opaque) { daemonClientEventCallback *callback = opaque; - remote_domain_event_rtc_change_msg data; + remote_domain_event_rtc_change_msg data = { 0 };
if (callback->callbackID < 0 || !remoteRelayDomainEventCheckACL(callback->client, conn, dom)) @@ -400,7 +398,6 @@ remoteRelayDomainEventRTCChange(virConnectPtr conn, callback->callbackID, callback->legacy);
/* build return data */ - memset(&data, 0, sizeof(data)); make_nonnull_domain(&data.dom, dom); data.offset = offset;
@@ -428,7 +425,7 @@ remoteRelayDomainEventWatchdog(virConnectPtr conn, void *opaque) { daemonClientEventCallback *callback = opaque; - remote_domain_event_watchdog_msg data; + remote_domain_event_watchdog_msg data = { 0 };
if (callback->callbackID < 0 || !remoteRelayDomainEventCheckACL(callback->client, conn, dom)) @@ -438,7 +435,6 @@ remoteRelayDomainEventWatchdog(virConnectPtr conn, dom->name, dom->id, action, callback->callbackID);
/* build return data */ - memset(&data, 0, sizeof(data)); make_nonnull_domain(&data.dom, dom); data.action = action;
@@ -468,7 +464,7 @@ remoteRelayDomainEventIOError(virConnectPtr conn, void *opaque) { daemonClientEventCallback *callback = opaque; - remote_domain_event_io_error_msg data; + remote_domain_event_io_error_msg data = { 0 };
if (callback->callbackID < 0 || !remoteRelayDomainEventCheckACL(callback->client, conn, dom)) @@ -479,7 +475,6 @@ remoteRelayDomainEventIOError(virConnectPtr conn, callback->callbackID);
/* build return data */ - memset(&data, 0, sizeof(data)); data.srcPath = g_strdup(srcPath); data.devAlias = g_strdup(devAlias); make_nonnull_domain(&data.dom, dom); @@ -512,7 +507,7 @@ remoteRelayDomainEventIOErrorReason(virConnectPtr conn, void *opaque) { daemonClientEventCallback *callback = opaque; - remote_domain_event_io_error_reason_msg data; + remote_domain_event_io_error_reason_msg data = { 0 };
if (callback->callbackID < 0 || !remoteRelayDomainEventCheckACL(callback->client, conn, dom)) @@ -523,7 +518,6 @@ remoteRelayDomainEventIOErrorReason(virConnectPtr conn, callback->callbackID);
/* build return data */ - memset(&data, 0, sizeof(data)); data.srcPath = g_strdup(srcPath); data.devAlias = g_strdup(devAlias); data.reason = g_strdup(reason); @@ -558,7 +552,7 @@ remoteRelayDomainEventGraphics(virConnectPtr conn, void *opaque) { daemonClientEventCallback *callback = opaque; - remote_domain_event_graphics_msg data; + remote_domain_event_graphics_msg data = { 0 }; size_t i;
if (callback->callbackID < 0 || @@ -576,7 +570,6 @@ remoteRelayDomainEventGraphics(virConnectPtr conn, VIR_DEBUG(" %s=%s", subject->identities[i].type, subject->identities[i].name);
/* build return data */ - memset(&data, 0, sizeof(data)); data.phase = phase; data.local.family = local->family; data.remote.family = remote->family; @@ -625,7 +618,7 @@ remoteRelayDomainEventBlockJob(virConnectPtr conn, void *opaque) { daemonClientEventCallback *callback = opaque; - remote_domain_event_block_job_msg data; + remote_domain_event_block_job_msg data = { 0 };
if (callback->callbackID < 0 || !remoteRelayDomainEventCheckACL(callback->client, conn, dom)) @@ -635,7 +628,6 @@ remoteRelayDomainEventBlockJob(virConnectPtr conn, dom->name, dom->id, path, type, status, callback->callbackID);
/* build return data */ - memset(&data, 0, sizeof(data)); data.path = g_strdup(path); data.type = type; data.status = status; @@ -664,7 +656,7 @@ remoteRelayDomainEventControlError(virConnectPtr conn, void *opaque) { daemonClientEventCallback *callback = opaque; - remote_domain_event_control_error_msg data; + remote_domain_event_control_error_msg data = { 0 };
if (callback->callbackID < 0 || !remoteRelayDomainEventCheckACL(callback->client, conn, dom)) @@ -674,7 +666,6 @@ remoteRelayDomainEventControlError(virConnectPtr conn, dom->name, dom->id, callback->callbackID);
/* build return data */ - memset(&data, 0, sizeof(data)); make_nonnull_domain(&data.dom, dom);
if (callback->legacy) { @@ -704,7 +695,7 @@ remoteRelayDomainEventDiskChange(virConnectPtr conn, void *opaque) { daemonClientEventCallback *callback = opaque; - remote_domain_event_disk_change_msg data; + remote_domain_event_disk_change_msg data = { 0 };
if (callback->callbackID < 0 || !remoteRelayDomainEventCheckACL(callback->client, conn, dom)) @@ -715,7 +706,6 @@ remoteRelayDomainEventDiskChange(virConnectPtr conn, callback->callbackID);
/* build return data */ - memset(&data, 0, sizeof(data)); if (oldSrcPath) { data.oldSrcPath = g_new0(remote_nonnull_string, 1); *(data.oldSrcPath) = g_strdup(oldSrcPath); @@ -755,7 +745,7 @@ remoteRelayDomainEventTrayChange(virConnectPtr conn, void *opaque) { daemonClientEventCallback *callback = opaque; - remote_domain_event_tray_change_msg data; + remote_domain_event_tray_change_msg data = { 0 };
if (callback->callbackID < 0 || !remoteRelayDomainEventCheckACL(callback->client, conn, dom)) @@ -765,8 +755,6 @@ remoteRelayDomainEventTrayChange(virConnectPtr conn, dom->name, dom->id, devAlias, reason, callback->callbackID);
/* build return data */ - memset(&data, 0, sizeof(data)); - data.devAlias = g_strdup(devAlias); data.reason = reason; make_nonnull_domain(&data.dom, dom); @@ -794,7 +782,7 @@ remoteRelayDomainEventPMWakeup(virConnectPtr conn, void *opaque) { daemonClientEventCallback *callback = opaque; - remote_domain_event_pmwakeup_msg data; + remote_domain_event_pmwakeup_msg data = { 0 };
if (callback->callbackID < 0 || !remoteRelayDomainEventCheckACL(callback->client, conn, dom)) @@ -804,7 +792,6 @@ remoteRelayDomainEventPMWakeup(virConnectPtr conn, dom->name, dom->id, callback->callbackID);
/* build return data */ - memset(&data, 0, sizeof(data)); make_nonnull_domain(&data.dom, dom);
if (callback->legacy) { @@ -830,7 +817,7 @@ remoteRelayDomainEventPMSuspend(virConnectPtr conn, void *opaque) { daemonClientEventCallback *callback = opaque; - remote_domain_event_pmsuspend_msg data; + remote_domain_event_pmsuspend_msg data = { 0 };
if (callback->callbackID < 0 || !remoteRelayDomainEventCheckACL(callback->client, conn, dom)) @@ -840,7 +827,6 @@ remoteRelayDomainEventPMSuspend(virConnectPtr conn, dom->name, dom->id, callback->callbackID);
/* build return data */ - memset(&data, 0, sizeof(data)); make_nonnull_domain(&data.dom, dom);
if (callback->legacy) { @@ -866,7 +852,7 @@ remoteRelayDomainEventBalloonChange(virConnectPtr conn, void *opaque) { daemonClientEventCallback *callback = opaque; - remote_domain_event_balloon_change_msg data; + remote_domain_event_balloon_change_msg data = { 0 };
if (callback->callbackID < 0 || !remoteRelayDomainEventCheckACL(callback->client, conn, dom)) @@ -876,7 +862,6 @@ remoteRelayDomainEventBalloonChange(virConnectPtr conn, dom->name, dom->id, actual, callback->callbackID);
/* build return data */ - memset(&data, 0, sizeof(data)); make_nonnull_domain(&data.dom, dom); data.actual = actual;
@@ -904,7 +889,7 @@ remoteRelayDomainEventPMSuspendDisk(virConnectPtr conn, void *opaque) { daemonClientEventCallback *callback = opaque; - remote_domain_event_pmsuspend_disk_msg data; + remote_domain_event_pmsuspend_disk_msg data = { 0 };
if (callback->callbackID < 0 || !remoteRelayDomainEventCheckACL(callback->client, conn, dom)) @@ -914,7 +899,6 @@ remoteRelayDomainEventPMSuspendDisk(virConnectPtr conn, dom->name, dom->id, callback->callbackID);
/* build return data */ - memset(&data, 0, sizeof(data)); make_nonnull_domain(&data.dom, dom);
if (callback->legacy) { @@ -940,7 +924,7 @@ remoteRelayDomainEventDeviceRemoved(virConnectPtr conn, void *opaque) { daemonClientEventCallback *callback = opaque; - remote_domain_event_device_removed_msg data; + remote_domain_event_device_removed_msg data = { 0 };
if (callback->callbackID < 0 || !remoteRelayDomainEventCheckACL(callback->client, conn, dom)) @@ -950,8 +934,6 @@ remoteRelayDomainEventDeviceRemoved(virConnectPtr conn, dom->name, dom->id, devAlias, callback->callbackID);
/* build return data */ - memset(&data, 0, sizeof(data)); - data.devAlias = g_strdup(devAlias);
make_nonnull_domain(&data.dom, dom); @@ -984,7 +966,7 @@ remoteRelayDomainEventBlockJob2(virConnectPtr conn, void *opaque) { daemonClientEventCallback *callback = opaque; - remote_domain_event_block_job_2_msg data; + remote_domain_event_block_job_2_msg data = { 0 };
if (callback->callbackID < 0 || !remoteRelayDomainEventCheckACL(callback->client, conn, dom)) @@ -994,7 +976,6 @@ remoteRelayDomainEventBlockJob2(virConnectPtr conn, dom->name, dom->id, dst, type, status, callback->callbackID);
/* build return data */ - memset(&data, 0, sizeof(data)); data.callbackID = callback->callbackID; data.dst = g_strdup(dst); data.type = type; @@ -1017,7 +998,7 @@ remoteRelayDomainEventTunable(virConnectPtr conn, void *opaque) { daemonClientEventCallback *callback = opaque; - remote_domain_event_callback_tunable_msg data; + remote_domain_event_callback_tunable_msg data = { 0 };
if (callback->callbackID < 0 || !remoteRelayDomainEventCheckACL(callback->client, conn, dom)) @@ -1027,8 +1008,6 @@ remoteRelayDomainEventTunable(virConnectPtr conn, dom->name, dom->id, callback->callbackID, params, nparams);
/* build return data */ - memset(&data, 0, sizeof(data)); - if (virTypedParamsSerialize(params, nparams, REMOTE_DOMAIN_EVENT_TUNABLE_MAX, (struct _virTypedParameterRemote **) &data.params.params_val, @@ -1057,7 +1036,7 @@ remoteRelayDomainEventAgentLifecycle(virConnectPtr conn, void *opaque) { daemonClientEventCallback *callback = opaque; - remote_domain_event_callback_agent_lifecycle_msg data; + remote_domain_event_callback_agent_lifecycle_msg data = { 0 };
if (callback->callbackID < 0 || !remoteRelayDomainEventCheckACL(callback->client, conn, dom)) @@ -1068,7 +1047,6 @@ remoteRelayDomainEventAgentLifecycle(virConnectPtr conn, dom->name, dom->id, callback->callbackID, state, reason);
/* build return data */ - memset(&data, 0, sizeof(data)); data.callbackID = callback->callbackID; make_nonnull_domain(&data.dom, dom); data.state = state; @@ -1090,7 +1068,7 @@ remoteRelayDomainEventDeviceAdded(virConnectPtr conn, void *opaque) { daemonClientEventCallback *callback = opaque; - remote_domain_event_callback_device_added_msg data; + remote_domain_event_callback_device_added_msg data = { 0 };
if (callback->callbackID < 0 || !remoteRelayDomainEventCheckACL(callback->client, conn, dom)) @@ -1100,8 +1078,6 @@ remoteRelayDomainEventDeviceAdded(virConnectPtr conn, dom->name, dom->id, devAlias, callback->callbackID);
/* build return data */ - memset(&data, 0, sizeof(data)); - data.devAlias = g_strdup(devAlias); make_nonnull_domain(&data.dom, dom); data.callbackID = callback->callbackID; @@ -1122,7 +1098,7 @@ remoteRelayDomainEventMigrationIteration(virConnectPtr conn, void *opaque) { daemonClientEventCallback *callback = opaque; - remote_domain_event_callback_migration_iteration_msg data; + remote_domain_event_callback_migration_iteration_msg data = { 0 };
if (callback->callbackID < 0 || !remoteRelayDomainEventCheckACL(callback->client, conn, dom)) @@ -1133,7 +1109,6 @@ remoteRelayDomainEventMigrationIteration(virConnectPtr conn, dom->name, dom->id, callback->callbackID, iteration);
/* build return data */ - memset(&data, 0, sizeof(data)); data.callbackID = callback->callbackID; make_nonnull_domain(&data.dom, dom);
@@ -1156,7 +1131,7 @@ remoteRelayDomainEventJobCompleted(virConnectPtr conn, void *opaque) { daemonClientEventCallback *callback = opaque; - remote_domain_event_callback_job_completed_msg data; + remote_domain_event_callback_job_completed_msg data = { 0 };
if (callback->callbackID < 0 || !remoteRelayDomainEventCheckACL(callback->client, conn, dom)) @@ -1167,8 +1142,6 @@ remoteRelayDomainEventJobCompleted(virConnectPtr conn, dom->name, dom->id, callback->callbackID, params, nparams);
/* build return data */ - memset(&data, 0, sizeof(data)); - if (virTypedParamsSerialize(params, nparams, REMOTE_DOMAIN_JOB_STATS_MAX, (struct _virTypedParameterRemote **) &data.params.params_val, @@ -1194,7 +1167,7 @@ remoteRelayDomainEventDeviceRemovalFailed(virConnectPtr conn, void *opaque) { daemonClientEventCallback *callback = opaque; - remote_domain_event_callback_device_removal_failed_msg data; + remote_domain_event_callback_device_removal_failed_msg data = { 0 };
if (callback->callbackID < 0 || !remoteRelayDomainEventCheckACL(callback->client, conn, dom)) @@ -1204,8 +1177,6 @@ remoteRelayDomainEventDeviceRemovalFailed(virConnectPtr conn, dom->name, dom->id, devAlias, callback->callbackID);
/* build return data */ - memset(&data, 0, sizeof(data)); - data.devAlias = g_strdup(devAlias);
make_nonnull_domain(&data.dom, dom); @@ -1228,7 +1199,7 @@ remoteRelayDomainEventMetadataChange(virConnectPtr conn, void *opaque) { daemonClientEventCallback *callback = opaque; - remote_domain_event_callback_metadata_change_msg data; + remote_domain_event_callback_metadata_change_msg data = { 0 };
if (callback->callbackID < 0 || !remoteRelayDomainEventCheckACL(callback->client, conn, dom)) @@ -1238,8 +1209,6 @@ remoteRelayDomainEventMetadataChange(virConnectPtr conn, dom->name, dom->id, type, NULLSTR(nsuri), callback->callbackID);
/* build return data */ - memset(&data, 0, sizeof(data)); - data.type = type; if (nsuri) { data.nsuri = g_new0(remote_nonnull_string, 1); @@ -1268,7 +1237,7 @@ remoteRelayDomainEventBlockThreshold(virConnectPtr conn, void *opaque) { daemonClientEventCallback *callback = opaque; - remote_domain_event_block_threshold_msg data; + remote_domain_event_block_threshold_msg data = { 0 };
if (callback->callbackID < 0 || !remoteRelayDomainEventCheckACL(callback->client, conn, dom)) @@ -1278,7 +1247,6 @@ remoteRelayDomainEventBlockThreshold(virConnectPtr conn, dom->name, dom->id, dev, NULLSTR(path), threshold, excess, callback->callbackID);
/* build return data */ - memset(&data, 0, sizeof(data)); data.callbackID = callback->callbackID; data.dev = g_strdup(dev); if (path) { @@ -1306,14 +1274,13 @@ remoteRelayDomainEventMemoryFailure(virConnectPtr conn, void *opaque) { daemonClientEventCallback *callback = opaque; - remote_domain_event_memory_failure_msg data; + remote_domain_event_memory_failure_msg data = { 0 };
if (callback->callbackID < 0 || !remoteRelayDomainEventCheckACL(callback->client, conn, dom)) return -1;
/* build return data */ - memset(&data, 0, sizeof(data)); data.callbackID = callback->callbackID; data.recipient = recipient; data.action = action; @@ -1336,14 +1303,13 @@ remoteRelayDomainEventMemoryDeviceSizeChange(virConnectPtr conn, void *opaque) { daemonClientEventCallback *callback = opaque; - remote_domain_event_memory_device_size_change_msg data; + remote_domain_event_memory_device_size_change_msg data = { 0 };
if (callback->callbackID < 0 || !remoteRelayDomainEventCheckACL(callback->client, conn, dom)) return -1;
/* build return data */ - memset(&data, 0, sizeof(data)); data.callbackID = callback->callbackID; data.alias = g_strdup(alias); data.size = size; @@ -1397,7 +1363,7 @@ remoteRelayNetworkEventLifecycle(virConnectPtr conn, void *opaque) { daemonClientEventCallback *callback = opaque; - remote_network_event_lifecycle_msg data; + remote_network_event_lifecycle_msg data = { 0 };
if (callback->callbackID < 0 || !remoteRelayNetworkEventCheckACL(callback->client, conn, net)) @@ -1407,7 +1373,6 @@ remoteRelayNetworkEventLifecycle(virConnectPtr conn, event, detail, callback->callbackID);
/* build return data */ - memset(&data, 0, sizeof(data)); make_nonnull_network(&data.net, net); data.callbackID = callback->callbackID; data.event = event; @@ -1434,7 +1399,7 @@ remoteRelayStoragePoolEventLifecycle(virConnectPtr conn, void *opaque) { daemonClientEventCallback *callback = opaque; - remote_storage_pool_event_lifecycle_msg data; + remote_storage_pool_event_lifecycle_msg data = { 0 };
if (callback->callbackID < 0 || !remoteRelayStoragePoolEventCheckACL(callback->client, conn, pool)) @@ -1444,7 +1409,6 @@ remoteRelayStoragePoolEventLifecycle(virConnectPtr conn, event, detail, callback->callbackID);
/* build return data */ - memset(&data, 0, sizeof(data)); make_nonnull_storage_pool(&data.pool, pool); data.callbackID = callback->callbackID; data.event = event; @@ -1464,7 +1428,7 @@ remoteRelayStoragePoolEventRefresh(virConnectPtr conn, void *opaque) { daemonClientEventCallback *callback = opaque; - remote_storage_pool_event_refresh_msg data; + remote_storage_pool_event_refresh_msg data = { 0 };
if (callback->callbackID < 0 || !remoteRelayStoragePoolEventCheckACL(callback->client, conn, pool)) @@ -1474,7 +1438,6 @@ remoteRelayStoragePoolEventRefresh(virConnectPtr conn, callback->callbackID);
/* build return data */ - memset(&data, 0, sizeof(data)); make_nonnull_storage_pool(&data.pool, pool); data.callbackID = callback->callbackID;
@@ -1501,7 +1464,7 @@ remoteRelayNodeDeviceEventLifecycle(virConnectPtr conn, void *opaque) { daemonClientEventCallback *callback = opaque; - remote_node_device_event_lifecycle_msg data; + remote_node_device_event_lifecycle_msg data = { 0 };
if (callback->callbackID < 0 || !remoteRelayNodeDeviceEventCheckACL(callback->client, conn, dev)) @@ -1511,7 +1474,6 @@ remoteRelayNodeDeviceEventLifecycle(virConnectPtr conn, event, detail, callback->callbackID);
/* build return data */ - memset(&data, 0, sizeof(data)); make_nonnull_node_device(&data.dev, dev); data.callbackID = callback->callbackID; data.event = event; @@ -1531,7 +1493,7 @@ remoteRelayNodeDeviceEventUpdate(virConnectPtr conn, void *opaque) { daemonClientEventCallback *callback = opaque; - remote_node_device_event_update_msg data; + remote_node_device_event_update_msg data = { 0 };
if (callback->callbackID < 0 || !remoteRelayNodeDeviceEventCheckACL(callback->client, conn, dev)) @@ -1541,7 +1503,6 @@ remoteRelayNodeDeviceEventUpdate(virConnectPtr conn, callback->callbackID);
/* build return data */ - memset(&data, 0, sizeof(data)); make_nonnull_node_device(&data.dev, dev); data.callbackID = callback->callbackID;
@@ -1568,7 +1529,7 @@ remoteRelaySecretEventLifecycle(virConnectPtr conn, void *opaque) { daemonClientEventCallback *callback = opaque; - remote_secret_event_lifecycle_msg data; + remote_secret_event_lifecycle_msg data = { 0 };
if (callback->callbackID < 0 || !remoteRelaySecretEventCheckACL(callback->client, conn, secret)) @@ -1578,7 +1539,6 @@ remoteRelaySecretEventLifecycle(virConnectPtr conn, event, detail, callback->callbackID);
/* build return data */ - memset(&data, 0, sizeof(data)); make_nonnull_secret(&data.secret, secret); data.callbackID = callback->callbackID; data.event = event; @@ -1598,7 +1558,7 @@ remoteRelaySecretEventValueChanged(virConnectPtr conn, void *opaque) { daemonClientEventCallback *callback = opaque; - remote_secret_event_value_changed_msg data; + remote_secret_event_value_changed_msg data = { 0 };
if (callback->callbackID < 0 || !remoteRelaySecretEventCheckACL(callback->client, conn, secret)) @@ -1608,7 +1568,6 @@ remoteRelaySecretEventValueChanged(virConnectPtr conn, callback->callbackID);
/* build return data */ - memset(&data, 0, sizeof(data)); make_nonnull_secret(&data.secret, secret); data.callbackID = callback->callbackID;
@@ -1637,7 +1596,7 @@ remoteRelayDomainQemuMonitorEvent(virConnectPtr conn, void *opaque) { daemonClientEventCallback *callback = opaque; - qemu_domain_monitor_event_msg data; + qemu_domain_monitor_event_msg data = { 0 };
if (callback->callbackID < 0 || !remoteRelayDomainQemuMonitorEventCheckACL(callback->client, conn, @@ -1648,7 +1607,6 @@ remoteRelayDomainQemuMonitorEvent(virConnectPtr conn, event, details, callback->callbackID);
/* build return data */ - memset(&data, 0, sizeof(data)); data.callbackID = callback->callbackID; data.event = g_strdup(event); data.seconds = seconds; @@ -2677,14 +2635,13 @@ remoteDispatchNodeGetSecurityModel(virNetServer *server G_GNUC_UNUSED, struct virNetMessageError *rerr, remote_node_get_security_model_ret *ret) { - virSecurityModel secmodel; + virSecurityModel secmodel = { 0 }; int rv = -1; virConnectPtr conn = remoteGetHypervisorConn(client);
if (!conn) goto cleanup;
- memset(&secmodel, 0, sizeof(secmodel)); if (virNodeGetSecurityModel(conn, &secmodel) < 0) goto cleanup;
diff --git a/src/remote/remote_daemon_stream.c b/src/remote/remote_daemon_stream.c index f52af790c1..1a89ff822c 100644 --- a/src/remote/remote_daemon_stream.c +++ b/src/remote/remote_daemon_stream.c @@ -226,12 +226,11 @@ daemonStreamEvent(virStreamPtr st, int events, void *opaque) (events & (VIR_STREAM_EVENT_ERROR | VIR_STREAM_EVENT_HANGUP))) { int ret; virNetMessage *msg; - virNetMessageError rerr; + virNetMessageError rerr = { 0 }; virErrorPtr origErr;
virErrorPreserveLast(&origErr);
- memset(&rerr, 0, sizeof(rerr)); stream->closed = true; virStreamEventRemoveCallback(stream->st); virStreamAbort(stream->st); @@ -565,13 +564,11 @@ daemonStreamHandleWriteData(virNetServerClient *client, /* Blocking, so indicate we have more todo later */ return 1; } else if (ret < 0) { - virNetMessageError rerr; + virNetMessageError rerr = { 0 }; virErrorPtr err;
virErrorPreserveLast(&err);
- memset(&rerr, 0, sizeof(rerr)); - VIR_INFO("Stream send failed"); stream->closed = true; virStreamEventRemoveCallback(stream->st); @@ -613,8 +610,8 @@ daemonStreamHandleFinish(virNetServerClient *client, ret = virStreamFinish(stream->st);
if (ret < 0) { - virNetMessageError rerr; - memset(&rerr, 0, sizeof(rerr)); + virNetMessageError rerr = { 0 }; + return virNetServerProgramSendReplyError(stream->prog, client, msg, @@ -663,8 +660,8 @@ daemonStreamHandleAbort(virNetServerClient *client, }
if (raise_error) { - virNetMessageError rerr; - memset(&rerr, 0, sizeof(rerr)); + virNetMessageError rerr = { 0 }; + return virNetServerProgramSendReplyError(stream->prog, client, msg, @@ -709,9 +706,7 @@ daemonStreamHandleHole(virNetServerClient *client, ret = virStreamSendHole(stream->st, data.length, data.flags);
if (ret < 0) { - virNetMessageError rerr; - - memset(&rerr, 0, sizeof(rerr)); + virNetMessageError rerr = { 0 };
VIR_INFO("Stream send hole failed"); stream->closed = true; @@ -825,7 +820,7 @@ daemonStreamHandleRead(virNetServerClient *client, daemonClientStream *stream) { virNetMessage *msg = NULL; - virNetMessageError rerr; + virNetMessageError rerr = { 0 }; char *buffer; size_t bufferLen = VIR_NET_MESSAGE_LEGACY_PAYLOAD_MAX; int ret = -1; @@ -848,8 +843,6 @@ daemonStreamHandleRead(virNetServerClient *client, if (!stream->tx) return 0;
- memset(&rerr, 0, sizeof(rerr)); - buffer = g_new0(char, bufferLen);
if (!(msg = virNetMessageNew(false))) diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index 7ccf550dff..8e78af0ea0 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -1184,10 +1184,9 @@ doRemoteOpen(virConnectPtr conn,
/* Now try and find out what URI the daemon used */ if (conn->uri == NULL) { - remote_connect_get_uri_ret uriret; + remote_connect_get_uri_ret uriret = { 0 };
VIR_DEBUG("Trying to query remote URI"); - memset(&uriret, 0, sizeof(uriret)); if (call(conn, priv, 0, REMOTE_PROC_CONNECT_GET_URI, (xdrproc_t) xdr_void, (char *) NULL, @@ -3725,9 +3724,9 @@ static int remoteAuthSASL(virConnectPtr conn, struct private_data *priv, virConnectAuthPtr auth, const char *wantmech) { - remote_auth_sasl_init_ret iret; + remote_auth_sasl_init_ret iret = { 0 }; remote_auth_sasl_start_args sargs = {0}; - remote_auth_sasl_start_ret sret; + remote_auth_sasl_start_ret sret = { 0 }; const char *clientout; char *serverin = NULL; size_t clientoutlen, serverinlen; @@ -3739,9 +3738,7 @@ remoteAuthSASL(virConnectPtr conn, struct private_data *priv, const char *mechlist; virNetSASLContext *saslCtxt; virNetSASLSession *sasl = NULL; - struct remoteAuthInteractState state; - - memset(&state, 0, sizeof(state)); + struct remoteAuthInteractState state = { 0 };
VIR_DEBUG("Client initialize SASL authentication");
@@ -3787,7 +3784,6 @@ remoteAuthSASL(virConnectPtr conn, struct private_data *priv, goto cleanup;
/* First call is to inquire about supported mechanisms in the server */ - memset(&iret, 0, sizeof(iret)); if (call(conn, priv, 0, REMOTE_PROC_AUTH_SASL_INIT, (xdrproc_t) xdr_void, (char *)NULL, (xdrproc_t) xdr_remote_auth_sasl_init_ret, (char *) &iret) != 0) @@ -3841,7 +3837,6 @@ remoteAuthSASL(virConnectPtr conn, struct private_data *priv, mech, clientoutlen, clientout);
/* Now send the initial auth data to the server */ - memset(&sret, 0, sizeof(sret)); if (call(conn, priv, 0, REMOTE_PROC_AUTH_SASL_START, (xdrproc_t) xdr_remote_auth_sasl_start_args, (char *) &sargs, (xdrproc_t) xdr_remote_auth_sasl_start_ret, (char *) &sret) != 0) diff --git a/src/rpc/virnetclientprogram.c b/src/rpc/virnetclientprogram.c index abc8e6798a..31eee72fc8 100644 --- a/src/rpc/virnetclientprogram.c +++ b/src/rpc/virnetclientprogram.c @@ -116,11 +116,9 @@ static int virNetClientProgramDispatchError(virNetClientProgram *prog G_GNUC_UNUSED, virNetMessage *msg) { - virNetMessageError err; + virNetMessageError err = { 0 }; int ret = -1;
- memset(&err, 0, sizeof(err)); - if (virNetMessageDecodePayload(msg, (xdrproc_t)xdr_virNetMessageError, &err) < 0) goto cleanup;
diff --git a/src/rpc/virnetclientstream.c b/src/rpc/virnetclientstream.c index 21e9332134..98034d737d 100644 --- a/src/rpc/virnetclientstream.c +++ b/src/rpc/virnetclientstream.c @@ -261,7 +261,7 @@ void virNetClientStreamSetClosed(virNetClientStream *st, int virNetClientStreamSetError(virNetClientStream *st, virNetMessage *msg) { - virNetMessageError err; + virNetMessageError err = { 0 }; int ret = -1;
virObjectLock(st); @@ -270,7 +270,6 @@ int virNetClientStreamSetError(virNetClientStream *st, VIR_DEBUG("Overwriting existing stream error %s", NULLSTR(st->err.message));
virResetError(&st->err); - memset(&err, 0, sizeof(err));
if (virNetMessageDecodePayload(msg, (xdrproc_t)xdr_virNetMessageError, &err) < 0) goto cleanup; @@ -444,13 +443,12 @@ virNetClientStreamHandleHole(virNetClient *client, virNetClientStream *st) { virNetMessage *msg; - virNetStreamHole data; + virNetStreamHole data = { 0 }; int ret = -1;
VIR_DEBUG("client=%p st=%p", client, st);
msg = st->rx; - memset(&data, 0, sizeof(data));
/* We should not be called unless there's VIR_NET_STREAM_HOLE * message at the head of the list. But doesn't hurt to check */ @@ -634,7 +632,7 @@ virNetClientStreamSendHole(virNetClientStream *st, unsigned int flags) { virNetMessage *msg = NULL; - virNetStreamHole data; + virNetStreamHole data = { 0 }; int ret = -1;
VIR_DEBUG("st=%p length=%llu", st, length); @@ -645,7 +643,6 @@ virNetClientStreamSendHole(virNetClientStream *st, return -1; }
- memset(&data, 0, sizeof(data)); data.length = length; data.flags = flags;
diff --git a/src/rpc/virnetdaemon.c b/src/rpc/virnetdaemon.c index d37984d207..9795418126 100644 --- a/src/rpc/virnetdaemon.c +++ b/src/rpc/virnetdaemon.c @@ -692,7 +692,7 @@ virNetDaemonAddSignalHandler(virNetDaemon *dmn, void *opaque) { g_autofree virNetDaemonSignal *sigdata = NULL; - struct sigaction sig_action; + struct sigaction sig_action = { 0 }; VIR_LOCK_GUARD lock = virObjectLockGuard(dmn);
if (virNetDaemonSignalSetup(dmn) < 0) @@ -706,7 +706,6 @@ virNetDaemonAddSignalHandler(virNetDaemon *dmn, sigdata->func = func; sigdata->opaque = opaque;
- memset(&sig_action, 0, sizeof(sig_action)); sig_action.sa_sigaction = virNetDaemonSignalHandler; sig_action.sa_flags = SA_SIGINFO; sigemptyset(&sig_action.sa_mask); diff --git a/src/rpc/virnetsaslcontext.c b/src/rpc/virnetsaslcontext.c index 7151225cc3..8692703117 100644 --- a/src/rpc/virnetsaslcontext.c +++ b/src/rpc/virnetsaslcontext.c @@ -331,7 +331,7 @@ int virNetSASLSessionSecProps(virNetSASLSession *sasl, int maxSSF, bool allowAnonymous) { - sasl_security_properties_t secprops; + sasl_security_properties_t secprops = { 0 }; int err; int ret = -1;
@@ -339,7 +339,6 @@ int virNetSASLSessionSecProps(virNetSASLSession *sasl, minSSF, maxSSF, allowAnonymous, sasl->maxbufsize);
virObjectLock(sasl); - memset(&secprops, 0, sizeof(secprops));
secprops.min_ssf = minSSF; secprops.max_ssf = maxSSF; diff --git a/src/rpc/virnetserverprogram.c b/src/rpc/virnetserverprogram.c index 2cce188a09..b1236bf49b 100644 --- a/src/rpc/virnetserverprogram.c +++ b/src/rpc/virnetserverprogram.c @@ -229,12 +229,11 @@ int virNetServerProgramUnknownError(virNetServerClient *client, virNetMessage *msg, struct virNetMessageHeader *req) { - virNetMessageError rerr; + virNetMessageError rerr = { 0 };
virReportError(VIR_ERR_RPC, _("Cannot find program %1$d version %2$d"), req->prog, req->vers);
- memset(&rerr, 0, sizeof(rerr)); return virNetServerProgramSendError(req->prog, req->vers, client, @@ -273,9 +272,7 @@ int virNetServerProgramDispatch(virNetServerProgram *prog, virNetMessage *msg) { int ret = -1; - virNetMessageError rerr; - - memset(&rerr, 0, sizeof(rerr)); + virNetMessageError rerr = { 0 };
VIR_DEBUG("prog=%d ver=%d type=%d status=%d serial=%u proc=%d", msg->header.prog, msg->header.vers, msg->header.type, @@ -369,12 +366,10 @@ virNetServerProgramDispatchCall(virNetServerProgram *prog, g_autofree char *ret = NULL; int rv = -1; virNetServerProgramProc *dispatcher = NULL; - virNetMessageError rerr; + virNetMessageError rerr = { 0 }; size_t i; g_autoptr(virIdentity) identity = NULL;
- memset(&rerr, 0, sizeof(rerr)); - if (msg->header.status != VIR_NET_OK) { virReportError(VIR_ERR_RPC, _("Unexpected message status %1$u"), @@ -533,11 +528,10 @@ int virNetServerProgramSendStreamHole(virNetServerProgram *prog, long long length, unsigned int flags) { - virNetStreamHole data; + virNetStreamHole data = { 0 };
VIR_DEBUG("client=%p msg=%p length=%lld", client, msg, length);
- memset(&data, 0, sizeof(data)); data.length = length; data.flags = flags;
diff --git a/src/rpc/virnetsocket.c b/src/rpc/virnetsocket.c index 910fb8dd67..b58f7a6b8f 100644 --- a/src/rpc/virnetsocket.c +++ b/src/rpc/virnetsocket.c @@ -143,11 +143,10 @@ virNetSocketCheckProtocolByLookup(const char *address, int family, bool *hasFamily) { - struct addrinfo hints; + struct addrinfo hints = { 0 }; struct addrinfo *ai = NULL; int gaierr;
- memset(&hints, 0, sizeof(hints)); hints.ai_family = family; hints.ai_flags = AI_PASSIVE | AI_ADDRCONFIG; hints.ai_socktype = SOCK_STREAM; @@ -313,7 +312,7 @@ int virNetSocketNewListenTCP(const char *nodename, virNetSocket **socks = NULL; size_t nsocks = 0; struct addrinfo *ai = NULL; - struct addrinfo hints; + struct addrinfo hints = { 0 }; int fd = -1; size_t i; int socketErrno = 0; @@ -326,7 +325,6 @@ int virNetSocketNewListenTCP(const char *nodename, *retsocks = NULL; *nretsocks = 0;
- memset(&hints, 0, sizeof(hints)); hints.ai_family = family; hints.ai_flags = AI_PASSIVE; hints.ai_socktype = SOCK_STREAM; @@ -353,9 +351,7 @@ int virNetSocketNewListenTCP(const char *nodename,
runp = ai; while (runp) { - virSocketAddr addr; - - memset(&addr, 0, sizeof(addr)); + virSocketAddr addr = { 0 };
if ((fd = socket(runp->ai_family, runp->ai_socktype, runp->ai_protocol)) < 0) { @@ -477,14 +473,12 @@ int virNetSocketNewListenUNIX(const char *path, gid_t grp, virNetSocket **retsock) { - virSocketAddr addr; + virSocketAddr addr = { 0 }; mode_t oldmask; int fd;
*retsock = NULL;
- memset(&addr, 0, sizeof(addr)); - addr.len = sizeof(addr.data.un);
if ((fd = socket(PF_UNIX, SOCK_STREAM, 0)) < 0) { @@ -553,11 +547,9 @@ int virNetSocketNewListenFD(int fd, bool unlinkUNIX, virNetSocket **retsock) { - virSocketAddr addr; + virSocketAddr addr = { 0 }; *retsock = NULL;
- memset(&addr, 0, sizeof(addr)); - addr.len = sizeof(addr.data); if (getsockname(fd, &addr.data.sa, &addr.len) < 0) { virReportSystemError(errno, "%s", _("Unable to get local socket name")); @@ -577,20 +569,16 @@ int virNetSocketNewConnectTCP(const char *nodename, virNetSocket **retsock) { struct addrinfo *ai = NULL; - struct addrinfo hints; + struct addrinfo hints = { 0 }; int fd = -1; - virSocketAddr localAddr; - virSocketAddr remoteAddr; + virSocketAddr localAddr = { 0 }; + virSocketAddr remoteAddr = { 0 }; struct addrinfo *runp; int savedErrno = ENOENT; int e;
*retsock = NULL;
- memset(&localAddr, 0, sizeof(localAddr)); - memset(&remoteAddr, 0, sizeof(remoteAddr)); - - memset(&hints, 0, sizeof(hints)); hints.ai_family = family; hints.ai_flags = AI_PASSIVE | AI_ADDRCONFIG | AI_V4MAPPED; hints.ai_socktype = SOCK_STREAM; @@ -666,17 +654,14 @@ int virNetSocketNewConnectUNIX(const char *path, VIR_AUTOCLOSE lockfd = -1; int fd = -1; int retries = 500; - virSocketAddr localAddr; - virSocketAddr remoteAddr; + virSocketAddr localAddr = { 0 }; + virSocketAddr remoteAddr = { 0 }; g_autofree char *rundir = NULL; int ret = -1; bool daemonLaunched = false;
VIR_DEBUG("path=%s spawnDaemonPath=%s", path, NULLSTR(spawnDaemonPath));
- memset(&localAddr, 0, sizeof(localAddr)); - memset(&remoteAddr, 0, sizeof(remoteAddr)); - remoteAddr.len = sizeof(remoteAddr.data.un);
if (spawnDaemonPath) { @@ -1168,8 +1153,8 @@ int virNetSocketNewConnectSockFD(int sockfd,
virNetSocket *virNetSocketNewPostExecRestart(virJSONValue *object) { - virSocketAddr localAddr; - virSocketAddr remoteAddr; + virSocketAddr localAddr = { 0 }; + virSocketAddr remoteAddr = { 0 }; int fd, thepid, errfd; bool isClient; bool unlinkUNIX; @@ -1201,9 +1186,6 @@ virNetSocket *virNetSocketNewPostExecRestart(virJSONValue *object) if (virJSONValueObjectGetBoolean(object, "unlinkUNIX", &unlinkUNIX) < 0) unlinkUNIX = !isClient;
- memset(&localAddr, 0, sizeof(localAddr)); - memset(&remoteAddr, 0, sizeof(remoteAddr)); - remoteAddr.len = sizeof(remoteAddr.data.stor); if (getsockname(fd, &remoteAddr.data.sa, &remoteAddr.len) < 0) { virReportSystemError(errno, "%s", _("Unable to get peer socket name")); @@ -2059,17 +2041,14 @@ int virNetSocketListen(virNetSocket *sock, int backlog) int virNetSocketAccept(virNetSocket *sock, virNetSocket **clientsock) { int fd = -1; - virSocketAddr localAddr; - virSocketAddr remoteAddr; + virSocketAddr localAddr = { 0 }; + virSocketAddr remoteAddr = { 0 }; int ret = -1;
virObjectLock(sock);
*clientsock = NULL;
- memset(&localAddr, 0, sizeof(localAddr)); - memset(&remoteAddr, 0, sizeof(remoteAddr)); - remoteAddr.len = sizeof(remoteAddr.data.stor); if ((fd = accept(sock->fd, &remoteAddr.data.sa, &remoteAddr.len)) < 0) { if (errno == ECONNABORTED || diff --git a/src/rpc/virnetsshsession.c b/src/rpc/virnetsshsession.c index 98be120a11..16d420467e 100644 --- a/src/rpc/virnetsshsession.c +++ b/src/rpc/virnetsshsession.c @@ -559,7 +559,7 @@ static int virNetSSHAuthenticatePrivkey(virNetSSHSession *sess, virNetSSHAuthMethod *priv) { - virConnectCredential retr_passphrase; + virConnectCredential retr_passphrase = { 0 }; size_t i; char *errmsg; int ret; @@ -594,7 +594,6 @@ virNetSSHAuthenticatePrivkey(virNetSSHSession *sess, return -1; }
- memset(&retr_passphrase, 0, sizeof(virConnectCredential)); retr_passphrase.type = -1;
for (i = 0; i < sess->cred->ncredtype; i++) { diff --git a/src/storage/storage_backend_logical.c b/src/storage/storage_backend_logical.c index 60dc68cf4b..9462ac6790 100644 --- a/src/storage/storage_backend_logical.c +++ b/src/storage/storage_backend_logical.c @@ -186,11 +186,9 @@ virStorageBackendLogicalParseVolExtents(virStorageVolDef *vol, */ for (i = 0; i < nextents; i++) { g_autofree char *offset_str = NULL; - virStorageVolSourceExtent extent; + virStorageVolSourceExtent extent = { 0 }; size_t j = (i * 2) + 1;
- memset(&extent, 0, sizeof(extent)); - offset_str = g_match_info_fetch(info, j + 1);
if (virStrToLong_ull(offset_str, NULL, 10, &offset) < 0) { @@ -503,13 +501,12 @@ static char * virStorageBackendLogicalFindPoolSources(const char *srcSpec G_GNUC_UNUSED, unsigned int flags) { - virStoragePoolSourceList sourceList; + virStoragePoolSourceList sourceList = { 0 }; size_t i; char *retval = NULL;
virCheckFlags(0, NULL);
- memset(&sourceList, 0, sizeof(sourceList)); sourceList.type = VIR_STORAGE_POOL_LOGICAL;
if (virStorageBackendLogicalGetPoolSources(&sourceList) < 0) @@ -549,13 +546,12 @@ static bool virStorageBackendLogicalMatchPoolSource(virStoragePoolObj *pool) { virStoragePoolDef *def = virStoragePoolObjGetDef(pool); - virStoragePoolSourceList sourceList; + virStoragePoolSourceList sourceList = { 0 }; virStoragePoolSource *thisSource = NULL; size_t i, j; int matchcount = 0; bool ret = false;
- memset(&sourceList, 0, sizeof(sourceList)); sourceList.type = VIR_STORAGE_POOL_LOGICAL;
if (virStorageBackendLogicalGetPoolSources(&sourceList) < 0) diff --git a/src/util/virarptable.c b/src/util/virarptable.c index 7f9fefc160..299dddd664 100644 --- a/src/util/virarptable.c +++ b/src/util/virarptable.c @@ -111,13 +111,12 @@ virArpTableGet(void)
if (tb[NDA_DST]) { g_autofree char *ipstr = NULL; - virSocketAddr virAddr; + virSocketAddr virAddr = { 0 };
VIR_REALLOC_N(table->t, num + 1); table->n = num + 1;
addr = RTA_DATA(tb[NDA_DST]); - memset(&virAddr, 0, sizeof(virAddr)); virAddr.len = sizeof(virAddr.data.inet4); virAddr.data.inet4.sin_family = AF_INET; virAddr.data.inet4.sin_addr = *(struct in_addr *)addr; diff --git a/src/util/virauth.c b/src/util/virauth.c index bd676858ce..e7a5f7f010 100644 --- a/src/util/virauth.c +++ b/src/util/virauth.c @@ -135,7 +135,7 @@ virAuthGetUsernamePath(const char *path, const char *hostname) { unsigned int ncred; - virConnectCredential cred; + virConnectCredential cred = { 0 }; g_autofree char *prompt = NULL; char *ret = NULL;
@@ -150,8 +150,6 @@ virAuthGetUsernamePath(const char *path, return NULL; }
- memset(&cred, 0, sizeof(virConnectCredential)); - if (defaultUsername != NULL) { prompt = g_strdup_printf(_("Enter username for %1$s [%2$s]"), hostname, defaultUsername); diff --git a/src/util/virbpf.c b/src/util/virbpf.c index 34abf6f9b4..78fa102b4d 100644 --- a/src/util/virbpf.c +++ b/src/util/virbpf.c @@ -35,9 +35,7 @@ virBPFCreateMap(unsigned int mapType, unsigned int valSize, unsigned int maxEntries) { - union bpf_attr attr; - - memset(&attr, 0, sizeof(attr)); + union bpf_attr attr = { 0 };
attr.map_type = mapType; attr.key_size = keySize; @@ -57,12 +55,10 @@ virBPFLoadProg(struct bpf_insn *insns, { g_autofree char *logbuf = NULL; int progfd = -1; - union bpf_attr attr; + union bpf_attr attr = { 0 };
logbuf = g_new0(char, LOG_BUF_SIZE);
- memset(&attr, 0, sizeof(attr)); - attr.prog_type = progType; attr.insn_cnt = insnCnt; attr.insns = (uintptr_t)insns; @@ -85,9 +81,7 @@ virBPFAttachProg(int progfd, int targetfd, int attachType) { - union bpf_attr attr; - - memset(&attr, 0, sizeof(attr)); + union bpf_attr attr = { 0 };
attr.target_fd = targetfd; attr.attach_bpf_fd = progfd; @@ -102,9 +96,7 @@ virBPFDetachProg(int progfd, int targetfd, int attachType) { - union bpf_attr attr; - - memset(&attr, 0, sizeof(attr)); + union bpf_attr attr = { 0 };
attr.target_fd = targetfd; attr.attach_bpf_fd = progfd; @@ -121,11 +113,9 @@ virBPFQueryProg(int targetfd, unsigned int *progcnt, void *progids) { - union bpf_attr attr; + union bpf_attr attr = { 0 }; int rc;
- memset(&attr, 0, sizeof(attr)); - attr.query.target_fd = targetfd; attr.query.attach_type = attachType; attr.query.prog_cnt = maxprogids; @@ -143,9 +133,7 @@ virBPFQueryProg(int targetfd, int virBPFGetProg(unsigned int id) { - union bpf_attr attr; - - memset(&attr, 0, sizeof(attr)); + union bpf_attr attr = { 0 };
attr.prog_id = id;
@@ -158,11 +146,9 @@ virBPFGetProgInfo(int progfd, struct bpf_prog_info *info, unsigned int **mapIDs) { - union bpf_attr attr; + union bpf_attr attr = { 0 }; int rc;
- memset(&attr, 0, sizeof(attr)); - attr.info.bpf_fd = progfd; attr.info.info_len = sizeof(struct bpf_prog_info); attr.info.info = (uintptr_t)info; @@ -200,9 +186,7 @@ virBPFGetProgInfo(int progfd, int virBPFGetMap(unsigned int id) { - union bpf_attr attr; - - memset(&attr, 0, sizeof(attr)); + union bpf_attr attr = { 0 };
attr.map_id = id;
@@ -214,9 +198,7 @@ int virBPFGetMapInfo(int mapfd, struct bpf_map_info *info) { - union bpf_attr attr; - - memset(&attr, 0, sizeof(attr)); + union bpf_attr attr = { 0 };
attr.info.bpf_fd = mapfd; attr.info.info_len = sizeof(struct bpf_map_info); @@ -231,9 +213,7 @@ virBPFLookupElem(int mapfd, void *key, void *val) { - union bpf_attr attr; - - memset(&attr, 0, sizeof(attr)); + union bpf_attr attr = { 0 };
attr.map_fd = mapfd; attr.key = (uintptr_t)key; @@ -248,9 +228,7 @@ virBPFGetNextElem(int mapfd, void *key, void *nextKey) { - union bpf_attr attr; - - memset(&attr, 0, sizeof(attr)); + union bpf_attr attr = { 0 };
attr.map_fd = mapfd; attr.key = (uintptr_t)key; @@ -265,9 +243,7 @@ virBPFUpdateElem(int mapfd, void *key, void *val) { - union bpf_attr attr; - - memset(&attr, 0, sizeof(attr)); + union bpf_attr attr = { 0 };
attr.map_fd = mapfd; attr.key = (uintptr_t)key; @@ -281,9 +257,7 @@ int virBPFDeleteElem(int mapfd, void *key) { - union bpf_attr attr; - - memset(&attr, 0, sizeof(attr)); + union bpf_attr attr = { 0 };
attr.map_fd = mapfd; attr.key = (uintptr_t)key; diff --git a/src/util/virdevmapper.c b/src/util/virdevmapper.c index 33cf3e202b..70ce0f0c23 100644 --- a/src/util/virdevmapper.c +++ b/src/util/virdevmapper.c @@ -128,12 +128,10 @@ static int virDMOpen(void) { VIR_AUTOCLOSE controlFD = -1; - struct dm_ioctl dm; + struct dm_ioctl dm = { 0 }; g_autofree char *tmp = NULL; int ret;
- memset(&dm, 0, sizeof(dm)); - if ((controlFD = open(CONTROL_PATH, O_RDWR)) < 0) { /* We can't talk to devmapper. Produce a warning and let * the caller decide what to do next. */ @@ -223,12 +221,10 @@ virDevMapperGetTargetsImpl(int controlFD, { g_autofree char *sanitizedPath = NULL; g_autofree char *buf = NULL; - struct dm_ioctl dm; + struct dm_ioctl dm = { 0 }; struct dm_target_deps *deps = NULL; size_t i;
- memset(&dm, 0, sizeof(dm)); - if (ttl == 0) { errno = ELOOP; return -1; diff --git a/src/util/virfdstream.c b/src/util/virfdstream.c index 0e39889ac9..26a1f00316 100644 --- a/src/util/virfdstream.c +++ b/src/util/virfdstream.c @@ -1192,7 +1192,7 @@ int virFDStreamConnectUNIX(virStreamPtr st, const char *path, bool abstract) { - struct sockaddr_un sa; + struct sockaddr_un sa = { 0 }; virTimeBackOffVar timeout; VIR_AUTOCLOSE fd = -1; int ret; @@ -1203,7 +1203,6 @@ int virFDStreamConnectUNIX(virStreamPtr st, return -1; }
- memset(&sa, 0, sizeof(sa)); sa.sun_family = AF_UNIX; if (abstract) { if (virStrcpy(sa.sun_path+1, path, sizeof(sa.sun_path)-1) < 0) diff --git a/src/util/virfile.c b/src/util/virfile.c index 2984e2ead2..fe456596ae 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -876,14 +876,13 @@ int virFileLoopDeviceAssociate(const char *file, { int lofd = -1; int fsfd = -1; - struct loop_info64 lo; + struct loop_info64 lo = { 0 }; g_autofree char *loname = NULL; int ret = -1;
if ((lofd = virFileLoopDeviceOpen(&loname)) < 0) return -1;
- memset(&lo, 0, sizeof(lo)); lo.lo_flags = LO_FLAGS_AUTOCLEAR;
/* Set backing file name for LOOP_GET_STATUS64 queries */ diff --git a/src/util/virinitctl.c b/src/util/virinitctl.c index 430f23a235..d26249a3e9 100644 --- a/src/util/virinitctl.c +++ b/src/util/virinitctl.c @@ -124,14 +124,12 @@ int virInitctlSetRunLevel(const char *fifo, virInitctlRunLevel level) { - struct virInitctlRequest req; + struct virInitctlRequest req = { 0 }; int fd = -1; int ret = -1; const int open_flags = O_WRONLY|O_NONBLOCK|O_CLOEXEC|O_NOCTTY; size_t i = 0;
- memset(&req, 0, sizeof(req)); - req.magic = VIR_INITCTL_MAGIC; req.sleeptime = 0; req.cmd = VIR_INITCTL_CMD_RUNLVL; diff --git a/src/util/viriscsi.c b/src/util/viriscsi.c index 4790bd4b55..a70c87cbdb 100644 --- a/src/util/viriscsi.c +++ b/src/util/viriscsi.c @@ -394,7 +394,7 @@ virISCSIScanTargetsInternal(const char *portal, "^\\s*(\\S+)\\s+(\\S+)\\s*$" }; int vars[] = { 2 }; - struct virISCSITargetList list; + struct virISCSITargetList list = { 0 }; size_t i; g_autoptr(virCommand) cmd = virCommandNewArgList(ISCSIADM, "--mode", "discovery", @@ -414,8 +414,6 @@ virISCSIScanTargetsInternal(const char *portal, NULL); }
- memset(&list, 0, sizeof(list)); - if (virCommandRunRegex(cmd, 1, regexes, diff --git a/src/util/virlog.c b/src/util/virlog.c index 6bbd69fe43..2d262d94f0 100644 --- a/src/util/virlog.c +++ b/src/util/virlog.c @@ -897,12 +897,12 @@ virLogOutputToJournald(virLogSource *source, { int buffd = -1; int journalfd = (intptr_t) data; - struct msghdr mh; - struct sockaddr_un sa; + struct msghdr mh = { 0 }; + struct sockaddr_un sa = { 0 }; union { struct cmsghdr cmsghdr; uint8_t buf[CMSG_SPACE(sizeof(int))]; - } control; + } control = { 0 }; struct cmsghdr *cmsg; /* We use /dev/shm instead of /tmp here, since we want this to * be a tmpfs, and one that is available from early boot on @@ -950,12 +950,10 @@ virLogOutputToJournald(virLogSource *source, } }
- memset(&sa, 0, sizeof(sa)); sa.sun_family = AF_UNIX; if (virStrcpyStatic(sa.sun_path, "/run/systemd/journal/socket") < 0) return;
- memset(&mh, 0, sizeof(mh)); mh.msg_name = &sa; mh.msg_namelen = offsetof(struct sockaddr_un, sun_path) + strlen(sa.sun_path); mh.msg_iov = iov; @@ -983,7 +981,6 @@ virLogOutputToJournald(virLogSource *source, mh.msg_iov = NULL; mh.msg_iovlen = 0;
- memset(&control, 0, sizeof(control)); mh.msg_control = &control; mh.msg_controllen = sizeof(control);
diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c index 38a4f480eb..46d90fbd76 100644 --- a/src/util/virnetdev.c +++ b/src/util/virnetdev.c @@ -812,9 +812,7 @@ virNetDevGetRcvAllMulti(const char *ifname, #if defined(WITH_IF_INDEXTONAME) char *virNetDevGetName(int ifindex) { - char name[IFNAMSIZ]; - - memset(&name, 0, sizeof(name)); + char name[IFNAMSIZ] = { 0 };
if (!if_indextoname(ifindex, name)) { virReportSystemError(errno, @@ -847,7 +845,7 @@ char *virNetDevGetName(int ifindex) #if defined(SIOCGIFINDEX) && defined(WITH_STRUCT_IFREQ) int virNetDevGetIndex(const char *ifname, int *ifindex) { - struct ifreq ifreq; + struct ifreq ifreq = { 0 }; VIR_AUTOCLOSE fd = socket(VIR_NETDEV_FAMILY, SOCK_DGRAM, 0);
if (fd < 0) { @@ -856,8 +854,6 @@ int virNetDevGetIndex(const char *ifname, int *ifindex) return -1; }
- memset(&ifreq, 0, sizeof(ifreq)); - if (virStrcpyStatic(ifreq.ifr_name, ifname) < 0) { virReportSystemError(ERANGE, _("invalid interface name %1$s"), diff --git a/src/util/virnetdevbridge.c b/src/util/virnetdevbridge.c index b870e26e5f..5fd88f3195 100644 --- a/src/util/virnetdevbridge.c +++ b/src/util/virnetdevbridge.c @@ -57,11 +57,9 @@ static int virNetDevBridgeCmd(const char *brname, void *arg, size_t argsize) { - struct ifdrv ifd; + struct ifdrv ifd = { 0 }; VIR_AUTOCLOSE s = -1;
- memset(&ifd, 0, sizeof(ifd)); - if ((s = socket(AF_LOCAL, SOCK_DGRAM, 0)) < 0) { virReportSystemError(errno, "%s", _("Cannot open network interface control socket")); @@ -621,9 +619,8 @@ int virNetDevBridgeAddPort(const char *brname, int virNetDevBridgeAddPort(const char *brname, const char *ifname) { - struct ifbreq req; + struct ifbreq req = { 0 };
- memset(&req, 0, sizeof(req)); if (virStrcpyStatic(req.ifbr_ifsname, ifname) < 0) { virReportSystemError(ERANGE, _("Network interface name '%1$s' is too long"), @@ -687,9 +684,8 @@ int virNetDevBridgeRemovePort(const char *brname, int virNetDevBridgeRemovePort(const char *brname, const char *ifname) { - struct ifbreq req; + struct ifbreq req = { 0 };
- memset(&req, 0, sizeof(req)); if (virStrcpyStatic(req.ifbr_ifsname, ifname) < 0) { virReportSystemError(ERANGE, _("Network interface name '%1$s' is too long"), diff --git a/src/util/virnetdevip.c b/src/util/virnetdevip.c index d1e717641c..3b02fe0cec 100644 --- a/src/util/virnetdevip.c +++ b/src/util/virnetdevip.c @@ -84,7 +84,7 @@ virNetDevCreateNetlinkAddressMessage(int messageType, virSocketAddr *peer) { struct nl_msg *nlmsg = NULL; - struct ifaddrmsg ifa; + struct ifaddrmsg ifa = { 0 }; unsigned int ifindex; void *addrData = NULL; void *peerData = NULL; @@ -110,8 +110,6 @@ virNetDevCreateNetlinkAddressMessage(int messageType, nlmsg = virNetlinkMsgNew(messageType, NLM_F_REQUEST | NLM_F_CREATE | NLM_F_EXCL);
- memset(&ifa, 0, sizeof(ifa)); - ifa.ifa_prefixlen = prefix; ifa.ifa_family = VIR_SOCKET_ADDR_FAMILY(addr); ifa.ifa_index = ifindex; @@ -277,7 +275,7 @@ virNetDevIPRouteAdd(const char *ifname, { unsigned int recvbuflen; unsigned int ifindex; - struct rtmsg rtmsg; + struct rtmsg rtmsg = { 0 }; void *gatewayData = NULL; void *addrData = NULL; size_t addrDataLen; @@ -323,8 +321,6 @@ virNetDevIPRouteAdd(const char *ifname, nlmsg = virNetlinkMsgNew(RTM_NEWROUTE, NLM_F_REQUEST | NLM_F_CREATE | NLM_F_EXCL);
- memset(&rtmsg, 0, sizeof(rtmsg)); - rtmsg.rtm_family = VIR_SOCKET_ADDR_FAMILY(gateway); rtmsg.rtm_table = RT_TABLE_MAIN; rtmsg.rtm_scope = RT_SCOPE_UNIVERSE; diff --git a/src/util/virnetdevtap.c b/src/util/virnetdevtap.c index 3e25f18770..3bfd36fc23 100644 --- a/src/util/virnetdevtap.c +++ b/src/util/virnetdevtap.c @@ -270,7 +270,7 @@ int virNetDevTapCreate(char **ifname, int virNetDevTapDelete(const char *ifname, const char *tunpath) { - struct ifreq try; + struct ifreq try = { 0 }; int fd; int ret = -1;
@@ -284,7 +284,6 @@ int virNetDevTapDelete(const char *ifname, return -1; }
- memset(&try, 0, sizeof(struct ifreq)); try.ifr_flags = IFF_TAP|IFF_NO_PI;
if (virStrcpyStatic(try.ifr_name, ifname) < 0) { diff --git a/src/util/virperf.c b/src/util/virperf.c index 03341e73e3..91f2ca632a 100644 --- a/src/util/virperf.c +++ b/src/util/virperf.c @@ -203,7 +203,7 @@ virPerfEventEnable(virPerf *perf, virPerfEventType type, pid_t pid) { - struct perf_event_attr attr; + struct perf_event_attr attr = { 0 }; struct virPerfEvent *event = &(perf->events[type]); struct virPerfEventAttr *event_attr = &attrs[type];
@@ -233,7 +233,6 @@ virPerfEventEnable(virPerf *perf, } }
- memset(&attr, 0, sizeof(attr)); attr.size = sizeof(attr); attr.inherit = 1; attr.disabled = 1; diff --git a/src/util/virprocess.c b/src/util/virprocess.c index a26683f333..f8daa786c9 100644 --- a/src/util/virprocess.c +++ b/src/util/virprocess.c @@ -1539,13 +1539,12 @@ virProcessExitWithStatus(int status) if (WIFEXITED(status)) { value = WEXITSTATUS(status); } else if (WIFSIGNALED(status)) { - struct sigaction act; + struct sigaction act = { 0 }; sigset_t sigs;
if (sigemptyset(&sigs) == 0 && sigaddset(&sigs, WTERMSIG(status)) == 0) sigprocmask(SIG_UNBLOCK, &sigs, NULL); - memset(&act, 0, sizeof(act)); act.sa_handler = SIG_DFL; sigfillset(&act.sa_mask); sigaction(WTERMSIG(status), &act, NULL); diff --git a/src/util/virsocket.c b/src/util/virsocket.c index a6f185114d..cd6f7ecd1b 100644 --- a/src/util/virsocket.c +++ b/src/util/virsocket.c @@ -389,12 +389,11 @@ virSocketSendFD(int sock, int fd) { char byte = 0; struct iovec iov; - struct msghdr msg; + struct msghdr msg = { 0 }; struct cmsghdr *cmsg; char buf[CMSG_SPACE(sizeof(fd))];
/* send at least one char */ - memset(&msg, 0, sizeof(msg)); iov.iov_base = &byte; iov.iov_len = 1; msg.msg_iov = &iov; @@ -428,7 +427,7 @@ virSocketRecvFD(int sock, int fdflags) { char byte = 0; struct iovec iov; - struct msghdr msg; + struct msghdr msg = { 0 }; int fd = -1; ssize_t len; struct cmsghdr *cmsg; @@ -441,7 +440,6 @@ virSocketRecvFD(int sock, int fdflags) }
/* send at least one char */ - memset(&msg, 0, sizeof(msg)); iov.iov_base = &byte; iov.iov_len = 1; msg.msg_iov = &iov; diff --git a/src/util/virsocketaddr.c b/src/util/virsocketaddr.c index 43511bdd69..fbda858cfe 100644 --- a/src/util/virsocketaddr.c +++ b/src/util/virsocketaddr.c @@ -92,7 +92,7 @@ virSocketAddrParseInternal(struct addrinfo **res, int ai_flags, bool reportError) { - struct addrinfo hints; + struct addrinfo hints = { 0 }; int err;
if (val == NULL) { @@ -101,7 +101,6 @@ virSocketAddrParseInternal(struct addrinfo **res, return -1; }
- memset(&hints, 0, sizeof(hints)); hints.ai_family = family; hints.ai_flags = ai_flags; if ((err = getaddrinfo(val, NULL, &hints, res)) != 0) { @@ -240,12 +239,10 @@ virSocketAddrParseIPv6(virSocketAddr *addr, const char *val) int virSocketAddrResolveService(const char *service) { struct addrinfo *res, *tmp; - struct addrinfo hints; + struct addrinfo hints = { 0 }; int err; int port = -1;
- memset(&hints, 0, sizeof(hints)); - if ((err = getaddrinfo(NULL, service, &hints, &res)) != 0) { virReportError(VIR_ERR_SYSTEM_ERROR, _("Cannot parse socket service '%1$s': %2$s"), diff --git a/src/util/viruri.c b/src/util/viruri.c index a824a983df..64995da342 100644 --- a/src/util/viruri.c +++ b/src/util/viruri.c @@ -201,12 +201,10 @@ virURIParse(const char *uri) char * virURIFormat(virURI *uri) { - xmlURI xmluri; + xmlURI xmluri = { 0 }; g_autofree char *tmpserver = NULL; char *ret;
- memset(&xmluri, 0, sizeof(xmluri)); - xmluri.scheme = uri->scheme; xmluri.server = uri->server; xmluri.port = uri->port; diff --git a/src/vbox/vbox_storage.c b/src/vbox/vbox_storage.c index 41b19a9c62..2285beea79 100644 --- a/src/vbox/vbox_storage.c +++ b/src/vbox/vbox_storage.c @@ -396,7 +396,7 @@ vboxStorageVolCreateXML(virStoragePoolPtr pool, struct _vboxDriver *data = pool->conn->privateData; PRUnichar *hddFormatUtf16 = NULL; PRUnichar *hddNameUtf16 = NULL; - virStoragePoolDef poolDef; + virStoragePoolDef poolDef = { 0 }; nsresult rc; vboxIID hddIID; unsigned char uuid[VIR_UUID_BUFLEN]; @@ -424,7 +424,6 @@ vboxStorageVolCreateXML(virStoragePoolPtr pool, * so just assign it for now, change the behaviour * when vbox supports pools. */ - memset(&poolDef, 0, sizeof(poolDef)); poolDef.type = VIR_STORAGE_POOL_DIR;
if ((def = virStorageVolDefParse(&poolDef, xml, NULL, parseFlags)) == NULL) @@ -720,8 +719,8 @@ static char *vboxStorageVolGetXMLDesc(virStorageVolPtr vol, unsigned int flags) char *hddFormatUtf8 = NULL; PRUint64 hddLogicalSize = 0; PRUint64 hddActualSize = 0; - virStoragePoolDef pool; - virStorageVolDef def; + virStoragePoolDef pool = { 0 }; + virStorageVolDef def = { 0 }; vboxIID hddIID; PRUint32 hddstate; nsresult rc; @@ -732,9 +731,6 @@ static char *vboxStorageVolGetXMLDesc(virStorageVolPtr vol, unsigned int flags)
virCheckFlags(0, NULL);
- memset(&pool, 0, sizeof(pool)); - memset(&def, 0, sizeof(def)); - if (virUUIDParse(vol->key, uuid) < 0) { virReportError(VIR_ERR_INVALID_ARG, _("Could not parse UUID from '%1$s'"), vol->key); diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c index 5e0f1b6b3e..fe4f253e9e 100644 --- a/src/vmx/vmx.c +++ b/src/vmx/vmx.c @@ -1044,11 +1044,9 @@ virVMXVerifyDiskAddress(virDomainXMLOption *xmlopt, virDomainDiskDef *disk, virDomainDef *vmdef) { - virDomainDiskDef def; + virDomainDiskDef def = { 0 }; virDomainDeviceDriveAddress *drive;
- memset(&def, 0, sizeof(def)); - if (disk->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Unsupported disk address type '%1$s'"), diff --git a/tests/nsstest.c b/tests/nsstest.c index 615b063118..4b7895db7e 100644 --- a/tests/nsstest.c +++ b/tests/nsstest.c @@ -39,14 +39,12 @@ testGetHostByName(const void *opaque) { const struct testNSSData *data = opaque; const bool existent = data->hostname && data->ipAddr && data->ipAddr[0]; - struct hostent resolved; + struct hostent resolved = { 0 }; char buf[BUF_SIZE] = { 0 }; char **addrList; int rv, tmp_errno = 0, tmp_herrno = 0; size_t i = 0;
- memset(&resolved, 0, sizeof(resolved)); - rv = NSS_NAME(gethostbyname2)(data->hostname, data->af, &resolved, @@ -116,12 +114,10 @@ testGetHostByName(const void *opaque) addrList = resolved.h_addr_list; i = 0; while (*addrList) { - virSocketAddr sa; + virSocketAddr sa = { 0 }; g_autofree char *ipAddr = NULL; void *address = *addrList;
- memset(&sa, 0, sizeof(sa)); - if (resolved.h_addrtype == AF_INET) { virSocketAddrSetIPv4AddrNetOrder(&sa, *((uint32_t *) address)); } else { diff --git a/tests/nwfilterxml2firewalltest.c b/tests/nwfilterxml2firewalltest.c index bd112cef83..b78b1b7947 100644 --- a/tests/nwfilterxml2firewalltest.c +++ b/tests/nwfilterxml2firewalltest.c @@ -348,12 +348,10 @@ static int testCompareXMLToArgvFiles(const char *xml, g_autofree char *actualargv = NULL; g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER; g_autoptr(GHashTable) vars = virHashNew(virNWFilterVarValueHashFree); - virNWFilterInst inst; + virNWFilterInst inst = { 0 }; int ret = -1; g_autoptr(virCommandDryRunToken) dryRunToken = virCommandDryRunTokenNew();
- memset(&inst, 0, sizeof(inst)); - virCommandSetDryRun(dryRunToken, &buf, true, true, NULL, NULL);
if (testSetDefaultParameters(vars) < 0) diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c index 4672b0a8ff..a1740d3f45 100644 --- a/tests/qemumonitorjsontest.c +++ b/tests/qemumonitorjsontest.c @@ -895,7 +895,7 @@ testQemuMonitorJSONGetObjectProperty(const void *opaque) { const testGenericData *data = opaque; virDomainXMLOption *xmlopt = data->xmlopt; - qemuMonitorJSONObjectProperty prop; + qemuMonitorJSONObjectProperty prop = { 0 }; g_autoptr(qemuMonitorTest) test = NULL;
if (!(test = qemuMonitorTestNewSchema(xmlopt, data->schema))) @@ -906,7 +906,6 @@ testQemuMonitorJSONGetObjectProperty(const void *opaque) return -1;
/* Present with path and property */ - memset(&prop, 0, sizeof(qemuMonitorJSONObjectProperty)); prop.type = QEMU_MONITOR_OBJECT_PROPERTY_BOOLEAN; if (qemuMonitorJSONGetObjectProperty(qemuMonitorTestGetMonitor(test), "/machine/i440fx", @@ -935,7 +934,7 @@ testQemuMonitorJSONSetObjectProperty(const void *opaque) { const testGenericData *data = opaque; virDomainXMLOption *xmlopt = data->xmlopt; - qemuMonitorJSONObjectProperty prop; + qemuMonitorJSONObjectProperty prop = { 0 }; g_autoptr(qemuMonitorTest) test = NULL;
if (!(test = qemuMonitorTestNewSchema(xmlopt, data->schema))) @@ -949,7 +948,6 @@ testQemuMonitorJSONSetObjectProperty(const void *opaque) return -1;
/* Let's attempt the setting */ - memset(&prop, 0, sizeof(qemuMonitorJSONObjectProperty)); prop.type = QEMU_MONITOR_OBJECT_PROPERTY_BOOLEAN; prop.val.b = true; if (qemuMonitorJSONSetObjectProperty(qemuMonitorTestGetMonitor(test), diff --git a/tests/qemumonitortestutils.c b/tests/qemumonitortestutils.c index 8b8b02a790..16a4096c98 100644 --- a/tests/qemumonitortestutils.c +++ b/tests/qemumonitortestutils.c @@ -874,9 +874,7 @@ qemuMonitorTestNew(virDomainXMLOption *xmlopt, GHashTable *schema) { g_autoptr(qemuMonitorTest) test = NULL; - virDomainChrSourceDef src; - - memset(&src, 0, sizeof(src)); + virDomainChrSourceDef src = { 0 };
if (!(test = qemuMonitorCommonTestNew(xmlopt, vm, &src))) goto error; @@ -1185,9 +1183,7 @@ qemuMonitorTest * qemuMonitorTestNewAgent(virDomainXMLOption *xmlopt) { g_autoptr(qemuMonitorTest) test = NULL; - virDomainChrSourceDef src; - - memset(&src, 0, sizeof(src)); + virDomainChrSourceDef src = { 0 };
if (!(test = qemuMonitorCommonTestNew(xmlopt, NULL, &src))) goto error; diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 534eb9e699..c44b9bc494 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -546,7 +546,7 @@ testCompareXMLToArgv(const void *data) unsigned int parseFlags = info->parseFlags; int ret = -1; virDomainObj *vm = NULL; - virDomainChrSourceDef monitor_chr; + virDomainChrSourceDef monitor_chr = { 0 }; g_autoptr(virConnect) conn = NULL; virError *err = NULL; g_autofree char *log = NULL; @@ -558,8 +558,6 @@ testCompareXMLToArgv(const void *data) virArch arch = VIR_ARCH_NONE; g_autoptr(virIdentity) sysident = virIdentityGetSystem();
- memset(&monitor_chr, 0, sizeof(monitor_chr)); - if (testQemuInfoInitArgs((struct testQemuInfo *) info) < 0) goto cleanup;
diff --git a/tests/virhostcputest.c b/tests/virhostcputest.c index 196f4c29b9..0990013878 100644 --- a/tests/virhostcputest.c +++ b/tests/virhostcputest.c @@ -30,7 +30,7 @@ linuxTestCompareFiles(const char *cpuinfofile, const char *outputfile) { g_autofree char *actualData = NULL; - virNodeInfo nodeinfo; + virNodeInfo nodeinfo = { 0 }; g_autoptr(FILE) cpuinfo = NULL;
cpuinfo = fopen(cpuinfofile, "r"); @@ -40,7 +40,6 @@ linuxTestCompareFiles(const char *cpuinfofile, return -1; }
- memset(&nodeinfo, 0, sizeof(nodeinfo)); if (virHostCPUGetInfoPopulateLinux(cpuinfo, arch, &nodeinfo.cpus, &nodeinfo.mhz, &nodeinfo.nodes, &nodeinfo.sockets, diff --git a/tests/virnetmessagetest.c b/tests/virnetmessagetest.c index 14790c0ece..e426bc7791 100644 --- a/tests/virnetmessagetest.c +++ b/tests/virnetmessagetest.c @@ -179,7 +179,7 @@ static int testMessageHeaderDecode(const void *args G_GNUC_UNUSED)
static int testMessagePayloadEncode(const void *args G_GNUC_UNUSED) { - virNetMessageError err; + virNetMessageError err = { 0 }; virNetMessage *msg = virNetMessageNew(true); int ret = -1; static const char expect[] = { @@ -218,8 +218,6 @@ static int testMessagePayloadEncode(const void *args G_GNUC_UNUSED) if (!msg) return -1;
- memset(&err, 0, sizeof(err)); - err.code = VIR_ERR_INTERNAL_ERROR; err.domain = VIR_FROM_RPC; err.level = VIR_ERR_ERROR; @@ -287,7 +285,7 @@ static int testMessagePayloadEncode(const void *args G_GNUC_UNUSED)
static int testMessagePayloadDecode(const void *args G_GNUC_UNUSED) { - virNetMessageError err; + virNetMessageError err = { 0 }; virNetMessage *msg = virNetMessageNew(true); static char input_buffer[] = { 0x00, 0x00, 0x00, 0x74, /* Length */ @@ -323,8 +321,6 @@ static int testMessagePayloadDecode(const void *args G_GNUC_UNUSED) }; int ret = -1;
- memset(&err, 0, sizeof(err)); - if (!msg) return -1;
diff --git a/tools/nss/libvirt_nss.c b/tools/nss/libvirt_nss.c index ec7763224b..ec14ac804b 100644 --- a/tools/nss/libvirt_nss.c +++ b/tools/nss/libvirt_nss.c @@ -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, diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index c74fc19347..89fdc7a050 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -1210,7 +1210,7 @@ cmdDominfo(vshControl *ctl, const vshCmd *cmd) { virDomainInfo info; g_autoptr(virshDomain) dom = NULL; - virSecurityModel secmodel; + virSecurityModel secmodel = { 0 }; int persistent = 0; bool ret = true; int autostart; @@ -1288,7 +1288,6 @@ cmdDominfo(vshControl *ctl, const vshCmd *cmd) has_managed_save ? _("yes") : _("no"));
/* Security model and label information */ - memset(&secmodel, 0, sizeof(secmodel)); if (virNodeGetSecurityModel(priv->conn, &secmodel) == -1) { if (last_error->code != VIR_ERR_NO_SUPPORT) { return false; diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index fb54562eb6..7d76055eda 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -6182,7 +6182,7 @@ virshDomainJobStatsToDomainJobInfo(virTypedParameterPtr params, static bool cmdDomjobinfo(vshControl *ctl, const vshCmd *cmd) { - virDomainJobInfo info; + virDomainJobInfo info = { 0 }; g_autoptr(virshDomain) dom = NULL; bool ret = false; const char *unit; @@ -6209,8 +6209,6 @@ cmdDomjobinfo(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptBool(cmd, "keep-completed")) flags |= VIR_DOMAIN_JOB_STATS_KEEP_COMPLETED;
- memset(&info, 0, sizeof(info)); - rc = virDomainGetJobStats(dom, &info.type, ¶ms, &nparams, flags); if (rc == 0) { if (virshDomainJobStatsToDomainJobInfo(params, nparams, &info) < 0) diff --git a/tools/vsh-table.c b/tools/vsh-table.c index 005cc564dd..da7dc84ee8 100644 --- a/tools/vsh-table.c +++ b/tools/vsh-table.c @@ -204,9 +204,7 @@ vshTableSafeEncode(const char *s, size_t *width) size_t sz = s ? strlen(s) : 0; char *buf; char *ret; - mbstate_t st; - - memset(&st, 0, sizeof(st)); + mbstate_t st = { 0 };
buf = g_new0(char, (sz * HEX_ENCODE_LENGTH) + 1);

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> --- src/libxl/libxl_capabilities.c | 4 +--- src/qemu/qemu_monitor.c | 4 +--- src/rpc/virnettlscontext.c | 3 +-- src/util/virnetlink.c | 4 +--- src/util/virutil.c | 4 ++-- src/vmx/vmx.c | 4 +--- tests/libxlmock.c | 4 +--- tests/qemumonitorjsontest.c | 5 ++--- tests/sockettest.c | 6 ++---- tools/nss/libvirt_nss.c | 7 +++---- tools/virsh-domain.c | 11 ++++------- 11 files changed, 19 insertions(+), 37 deletions(-) diff --git a/src/libxl/libxl_capabilities.c b/src/libxl/libxl_capabilities.c index 5ee6fe3f67..177e8b988e 100644 --- a/src/libxl/libxl_capabilities.c +++ b/src/libxl/libxl_capabilities.c @@ -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")); diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index db34b6c179..02da1d6dfc 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -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; diff --git a/src/rpc/virnettlscontext.c b/src/rpc/virnettlscontext.c index f72597ee80..1939fe5d6e 100644 --- a/src/rpc/virnettlscontext.c +++ b/src/rpc/virnettlscontext.c @@ -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; diff --git a/src/util/virnetlink.c b/src/util/virnetlink.c index d964c439b4..2d052cd03e 100644 --- a/src/util/virnetlink.c +++ b/src/util/virnetlink.c @@ -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; diff --git a/src/util/virutil.c b/src/util/virutil.c index 40ca205595..b5b65fb415 100644 --- a/src/util/virutil.c +++ b/src/util/virutil.c @@ -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); diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c index fe4f253e9e..5c6925be22 100644 --- a/src/vmx/vmx.c +++ b/src/vmx/vmx.c @@ -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'"), diff --git a/tests/libxlmock.c b/tests/libxlmock.c index 205d34df19..f564a0ef72 100644 --- a/tests/libxlmock.c +++ b/tests/libxlmock.c @@ -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) diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c index a1740d3f45..2e7b661db4 100644 --- a/tests/qemumonitorjsontest.c +++ b/tests/qemumonitorjsontest.c @@ -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; diff --git a/tests/sockettest.c b/tests/sockettest.c index 6b9063e11d..5cb8a9fb72 100644 --- a/tests/sockettest.c +++ b/tests/sockettest.c @@ -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; \ diff --git a/tools/nss/libvirt_nss.c b/tools/nss/libvirt_nss.c index ec14ac804b..5c4796e8bc 100644 --- a/tools/nss/libvirt_nss.c +++ b/tools/nss/libvirt_nss.c @@ -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)) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 7d76055eda..f8758f18a3 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -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; -- 2.41.0

On 8/3/23 12:36, Michal Privoznik wrote:
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> --- src/libxl/libxl_capabilities.c | 4 +--- src/qemu/qemu_monitor.c | 4 +--- src/rpc/virnettlscontext.c | 3 +-- src/util/virnetlink.c | 4 +--- src/util/virutil.c | 4 ++-- src/vmx/vmx.c | 4 +--- tests/libxlmock.c | 4 +--- tests/qemumonitorjsontest.c | 5 ++--- tests/sockettest.c | 6 ++---- tools/nss/libvirt_nss.c | 7 +++---- tools/virsh-domain.c | 11 ++++------- 11 files changed, 19 insertions(+), 37 deletions(-)
diff --git a/src/libxl/libxl_capabilities.c b/src/libxl/libxl_capabilities.c index 5ee6fe3f67..177e8b988e 100644 --- a/src/libxl/libxl_capabilities.c +++ b/src/libxl/libxl_capabilities.c @@ -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")); diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index db34b6c179..02da1d6dfc 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -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;
diff --git a/src/rpc/virnettlscontext.c b/src/rpc/virnettlscontext.c index f72597ee80..1939fe5d6e 100644 --- a/src/rpc/virnettlscontext.c +++ b/src/rpc/virnettlscontext.c @@ -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; diff --git a/src/util/virnetlink.c b/src/util/virnetlink.c index d964c439b4..2d052cd03e 100644 --- a/src/util/virnetlink.c +++ b/src/util/virnetlink.c @@ -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;
diff --git a/src/util/virutil.c b/src/util/virutil.c index 40ca205595..b5b65fb415 100644 --- a/src/util/virutil.c +++ b/src/util/virutil.c @@ -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); diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c index fe4f253e9e..5c6925be22 100644 --- a/src/vmx/vmx.c +++ b/src/vmx/vmx.c @@ -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'"), diff --git a/tests/libxlmock.c b/tests/libxlmock.c index 205d34df19..f564a0ef72 100644 --- a/tests/libxlmock.c +++ b/tests/libxlmock.c @@ -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) diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c index a1740d3f45..2e7b661db4 100644 --- a/tests/qemumonitorjsontest.c +++ b/tests/qemumonitorjsontest.c @@ -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; diff --git a/tests/sockettest.c b/tests/sockettest.c index 6b9063e11d..5cb8a9fb72 100644 --- a/tests/sockettest.c +++ b/tests/sockettest.c @@ -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; \ diff --git a/tools/nss/libvirt_nss.c b/tools/nss/libvirt_nss.c index ec14ac804b..5c4796e8bc 100644 --- a/tools/nss/libvirt_nss.c +++ b/tools/nss/libvirt_nss.c @@ -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;
&sentinel; (without the space) With this fixed, for this patch: Reviewed-by: Claudio Fontana <cfontana@suse.de>
+ 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)) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 7d76055eda..f8758f18a3 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -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;

If one of previous commits taught us something, it's that: sizeof(variable) and sizeof(type) are not the same. Especially because for live enough code the type might change (e.g. as we use autoptr more). And since we don't get any warnings when an incorrect length is passed to memset() it is easy to mess up. But with sizeof(variable) instead, it's not as easy. Therefore, switch to using memset(variable, 0, sizeof(*variable)), or its alternatives, depending on level of pointers. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/qemu/qemu_monitor_json.c | 4 ++-- src/qemu/qemu_process.c | 2 +- src/remote/remote_driver.c | 2 +- src/storage/storage_driver.c | 2 +- src/test/test_driver.c | 4 ++-- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 70536028ab..34c4b543e8 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -7112,7 +7112,7 @@ qemuMonitorJSONSetIOThread(qemuMonitor *mon, #define VIR_IOTHREAD_SET_PROP_UL(propName, propVal) \ if (iothreadInfo->set_##propVal) { \ - memset(&prop, 0, sizeof(qemuMonitorJSONObjectProperty)); \ + memset(&prop, 0, sizeof(prop)); \ prop.type = QEMU_MONITOR_OBJECT_PROPERTY_ULONG; \ prop.val.ul = iothreadInfo->propVal; \ if (qemuMonitorJSONSetObjectProperty(mon, path, propName, &prop) < 0) \ @@ -7145,7 +7145,7 @@ qemuMonitorJSONSetIOThread(qemuMonitor *mon, #define VIR_IOTHREAD_SET_PROP_INT(propName, propVal) \ if (iothreadInfo->set_##propVal) { \ - memset(&prop, 0, sizeof(qemuMonitorJSONObjectProperty)); \ + memset(&prop, 0, sizeof(prop)); \ prop.type = QEMU_MONITOR_OBJECT_PROPERTY_INT; \ prop.val.iv = iothreadInfo->propVal; \ if (qemuMonitorJSONSetObjectProperty(mon, path, propName, &prop) < 0) \ diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 572b842349..0644f80161 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -5068,7 +5068,7 @@ qemuProcessGraphicsSetupListen(virQEMUDriver *driver, * *_auto_unix_socket set we should use unix socket as * default instead of tcp listen. */ if (useSocket) { - memset(glisten, 0, sizeof(virDomainGraphicsListenDef)); + memset(glisten, 0, sizeof(*glisten)); glisten->socket = g_strdup_printf("%s/%s.sock", priv->libDir, type); glisten->fromConfig = true; diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index 8e78af0ea0..faad7292ed 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -2138,7 +2138,7 @@ remoteDomainGetVcpus(virDomainPtr domain, goto cleanup; } - memset(info, 0, sizeof(virVcpuInfo) * maxinfo); + memset(info, 0, sizeof(*info) * maxinfo); memset(cpumaps, 0, maxinfo * maplen); for (i = 0; i < ret.info.info_len; ++i) { diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c index c19abdd2f3..5a9dcbd193 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c @@ -1279,7 +1279,7 @@ storagePoolGetInfo(virStoragePoolPtr pool, if (virStorageBackendForType(def->type) == NULL) goto cleanup; - memset(info, 0, sizeof(virStoragePoolInfo)); + memset(info, 0, sizeof(*info)); if (virStoragePoolObjIsActive(obj)) info->state = VIR_STORAGE_POOL_RUNNING; else diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 3767908d9d..4b8e02c684 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -4826,7 +4826,7 @@ static int testDomainGetDiskErrors(virDomainPtr dom, if (errors) { /* sanitize input */ - memset(errors, 0, sizeof(virDomainDiskError) * nerrors); + memset(errors, 0, sizeof(*errors) * nerrors); for (i = 0; i < nerrors; i++) { errors[i].disk = g_strdup(vm->def->disks[i]->dst); @@ -6878,7 +6878,7 @@ testStoragePoolGetInfo(virStoragePoolPtr pool, return -1; def = virStoragePoolObjGetDef(obj); - memset(info, 0, sizeof(virStoragePoolInfo)); + memset(info, 0, sizeof(*info)); if (virStoragePoolObjIsActive(obj)) info->state = VIR_STORAGE_POOL_RUNNING; else -- 2.41.0

On 8/3/23 12:36, Michal Privoznik wrote:
If one of previous commits taught us something, it's that: sizeof(variable) and sizeof(type) are not the same. Especially because for live enough code the type might change (e.g. as we use autoptr more). And since we don't get any warnings when an incorrect length is passed to memset() it is easy to mess up. But with sizeof(variable) instead, it's not as easy. Therefore, switch to using memset(variable, 0, sizeof(*variable)), or its alternatives, depending on level of pointers.
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Claudio Fontana <cfontana@suse.de>
--- src/qemu/qemu_monitor_json.c | 4 ++-- src/qemu/qemu_process.c | 2 +- src/remote/remote_driver.c | 2 +- src/storage/storage_driver.c | 2 +- src/test/test_driver.c | 4 ++-- 5 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 70536028ab..34c4b543e8 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -7112,7 +7112,7 @@ qemuMonitorJSONSetIOThread(qemuMonitor *mon,
#define VIR_IOTHREAD_SET_PROP_UL(propName, propVal) \ if (iothreadInfo->set_##propVal) { \ - memset(&prop, 0, sizeof(qemuMonitorJSONObjectProperty)); \ + memset(&prop, 0, sizeof(prop)); \ prop.type = QEMU_MONITOR_OBJECT_PROPERTY_ULONG; \ prop.val.ul = iothreadInfo->propVal; \ if (qemuMonitorJSONSetObjectProperty(mon, path, propName, &prop) < 0) \ @@ -7145,7 +7145,7 @@ qemuMonitorJSONSetIOThread(qemuMonitor *mon,
#define VIR_IOTHREAD_SET_PROP_INT(propName, propVal) \ if (iothreadInfo->set_##propVal) { \ - memset(&prop, 0, sizeof(qemuMonitorJSONObjectProperty)); \ + memset(&prop, 0, sizeof(prop)); \ prop.type = QEMU_MONITOR_OBJECT_PROPERTY_INT; \ prop.val.iv = iothreadInfo->propVal; \ if (qemuMonitorJSONSetObjectProperty(mon, path, propName, &prop) < 0) \ diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 572b842349..0644f80161 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -5068,7 +5068,7 @@ qemuProcessGraphicsSetupListen(virQEMUDriver *driver, * *_auto_unix_socket set we should use unix socket as * default instead of tcp listen. */ if (useSocket) { - memset(glisten, 0, sizeof(virDomainGraphicsListenDef)); + memset(glisten, 0, sizeof(*glisten)); glisten->socket = g_strdup_printf("%s/%s.sock", priv->libDir, type); glisten->fromConfig = true; diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index 8e78af0ea0..faad7292ed 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -2138,7 +2138,7 @@ remoteDomainGetVcpus(virDomainPtr domain, goto cleanup; }
- memset(info, 0, sizeof(virVcpuInfo) * maxinfo); + memset(info, 0, sizeof(*info) * maxinfo); memset(cpumaps, 0, maxinfo * maplen);
for (i = 0; i < ret.info.info_len; ++i) { diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c index c19abdd2f3..5a9dcbd193 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c @@ -1279,7 +1279,7 @@ storagePoolGetInfo(virStoragePoolPtr pool, if (virStorageBackendForType(def->type) == NULL) goto cleanup;
- memset(info, 0, sizeof(virStoragePoolInfo)); + memset(info, 0, sizeof(*info)); if (virStoragePoolObjIsActive(obj)) info->state = VIR_STORAGE_POOL_RUNNING; else diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 3767908d9d..4b8e02c684 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -4826,7 +4826,7 @@ static int testDomainGetDiskErrors(virDomainPtr dom,
if (errors) { /* sanitize input */ - memset(errors, 0, sizeof(virDomainDiskError) * nerrors); + memset(errors, 0, sizeof(*errors) * nerrors);
for (i = 0; i < nerrors; i++) { errors[i].disk = g_strdup(vm->def->disks[i]->dst); @@ -6878,7 +6878,7 @@ testStoragePoolGetInfo(virStoragePoolPtr pool, return -1; def = virStoragePoolObjGetDef(obj);
- memset(info, 0, sizeof(virStoragePoolInfo)); + memset(info, 0, sizeof(*info)); if (virStoragePoolObjIsActive(obj)) info->state = VIR_STORAGE_POOL_RUNNING; else
participants (4)
-
Claudio Fontana
-
Michal Privoznik
-
Michal Prívozník
-
Olaf Hering