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(a)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);