lib: Finish using struct zero initializer manually

There are some cases left after previous commit which were not
picked up by coccinelle. Mostly, becuase the spatch was not
generic enough. We are left with cases like: two variables
declared on one line, a variable declared in #ifdef-s (there are
notoriously difficult for coccinelle), arrays, macro definitions,
etc.

Finish what coccinelle started, by hand.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Claudio Fontana <cfontana@suse.de>
This commit is contained in:
Michal Privoznik 2023-08-03 11:48:30 +02:00
parent b20a5e9a4d
commit 4f159d4269
11 changed files with 19 additions and 37 deletions

View File

@ -328,11 +328,9 @@ libxlCapsInitGuests(libxl_ctx *ctx, virCaps *caps)
char *saveptr = NULL;
size_t i;
struct guest_arch guest_archs[32];
struct guest_arch guest_archs[32] = { 0 };
int nr_guest_archs = 0;
memset(guest_archs, 0, sizeof(guest_archs));
if ((ver_info = libxl_get_version_info(ctx)) == NULL) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Failed to get version info from libxenlight"));

View File

@ -311,11 +311,9 @@ qemuMonitorIOWriteWithFD(qemuMonitor *mon,
struct msghdr msg = { 0 };
struct iovec iov[1];
int ret;
char control[CMSG_SPACE(sizeof(int))];
char control[CMSG_SPACE(sizeof(int))] = { 0 };
struct cmsghdr *cmsg;
memset(control, 0, sizeof(control));
iov[0].iov_base = (void *)data;
iov[0].iov_len = len;

View File

@ -545,12 +545,11 @@ static int virNetTLSContextSanityCheckCredentials(bool isServer,
const char *certFile)
{
gnutls_x509_crt_t cert = NULL;
gnutls_x509_crt_t cacerts[MAX_CERTS];
gnutls_x509_crt_t cacerts[MAX_CERTS] = { 0 };
size_t ncacerts = 0;
size_t i;
int ret = -1;
memset(cacerts, 0, sizeof(cacerts));
if ((access(certFile, R_OK) == 0) &&
!(cert = virNetTLSContextLoadCertFromFile(certFile, isServer)))
goto cleanup;

View File

@ -250,7 +250,7 @@ virNetlinkSendRequest(struct nl_msg *nl_msg, uint32_t src_pid,
int fd;
int n;
virNetlinkHandle *nlhandle = NULL;
struct pollfd fds[1];
struct pollfd fds[1] = { 0 };
struct nlmsghdr *nlmsg = nlmsg_hdr(nl_msg);
if (protocol >= MAX_LINKS) {
@ -286,8 +286,6 @@ virNetlinkSendRequest(struct nl_msg *nl_msg, uint32_t src_pid,
goto error;
}
memset(fds, 0, sizeof(fds));
fds[0].fd = fd;
fds[0].events = POLLIN;

View File

@ -428,7 +428,8 @@ virGetHostnameImpl(bool quiet)
{
int r;
char hostname[HOST_NAME_MAX+1], *result = NULL;
struct addrinfo hints, *info;
struct addrinfo hints = { 0 };
struct addrinfo *info;
r = gethostname(hostname, sizeof(hostname));
if (r == -1) {
@ -453,7 +454,6 @@ virGetHostnameImpl(bool quiet)
* canonicalize the hostname by running it through getaddrinfo
*/
memset(&hints, 0, sizeof(hints));
hints.ai_flags = AI_CANONNAME|AI_CANONIDN;
hints.ai_family = AF_UNSPEC;
r = getaddrinfo(hostname, NULL, &hints, &info);

View File

@ -3229,7 +3229,7 @@ virVMXFormatConfig(virVMXContext *ctx, virDomainXMLOption *xmlopt, virDomainDef
char *vmx = NULL;
size_t i;
int sched_cpu_affinity_length;
unsigned char zero[VIR_UUID_BUFLEN];
unsigned char zero[VIR_UUID_BUFLEN] = { 0 };
g_auto(virBuffer) buffer = VIR_BUFFER_INITIALIZER;
char *preliminaryDisplayName = NULL;
char *displayName = NULL;
@ -3247,8 +3247,6 @@ virVMXFormatConfig(virVMXContext *ctx, virDomainXMLOption *xmlopt, virDomainDef
return NULL;
}
memset(zero, 0, VIR_UUID_BUFLEN);
if (def->virtType != VIR_DOMAIN_VIRT_VMWARE) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Expecting virt type to be '%1$s' but found '%2$s'"),

View File

@ -60,9 +60,7 @@ VIR_MOCK_IMPL_RET_ARGS(libxl_get_version_info,
const libxl_version_info*,
libxl_ctx *, ctx)
{
static libxl_version_info info;
memset(&info, 0, sizeof(info));
static libxl_version_info info = { 0 };
/* silence gcc warning about unused function */
if (0)

View File

@ -1591,15 +1591,14 @@ testQemuMonitorJSONqemuMonitorJSONGetMigrationStats(const void *opaque)
{
const testGenericData *data = opaque;
virDomainXMLOption *xmlopt = data->xmlopt;
qemuMonitorMigrationStats stats, expectedStats;
qemuMonitorMigrationStats stats;
qemuMonitorMigrationStats expectedStats = { 0 };
g_autofree char *error = NULL;
g_autoptr(qemuMonitorTest) test = NULL;
if (!(test = qemuMonitorTestNewSchema(xmlopt, data->schema)))
return -1;
memset(&expectedStats, 0, sizeof(expectedStats));
expectedStats.status = QEMU_MONITOR_MIGRATION_STATUS_ACTIVE;
expectedStats.total_time = 47;
expectedStats.ram_total = 1611038720;

View File

@ -269,10 +269,9 @@ mymain(void)
#define DO_TEST_PARSE_AND_FORMAT(addrstr, family, pass) \
do { \
virSocketAddr addr; \
virSocketAddr addr = { 0 }; \
struct testParseData data = { &addr, addrstr, family, pass }; \
struct testFormatData data2 = { &addr, addrstr, pass }; \
memset(&addr, 0, sizeof(addr)); \
if (virTestRun("Test parse " addrstr " family " #family, \
testParseHelper, &data) < 0) \
ret = -1; \
@ -283,10 +282,9 @@ mymain(void)
#define DO_TEST_PARSE_AND_CHECK_FORMAT(addrstr, addrformated, family, pass) \
do { \
virSocketAddr addr; \
virSocketAddr addr = { 0 }; \
struct testParseData data = { &addr, addrstr, family, true}; \
struct testFormatData data2 = { &addr, addrformated, pass }; \
memset(&addr, 0, sizeof(addr)); \
if (virTestRun("Test parse " addrstr " family " #family, \
testParseHelper, &data) < 0) \
ret = -1; \

View File

@ -538,15 +538,14 @@ _nss_compat_getaddrinfo(void *retval,
void *mdata __attribute__((unused)),
va_list ap)
{
struct addrinfo sentinel, *cur, *ai;
struct addrinfo sentinel = { 0 };
struct addrinfo *cur = &sentinel;
struct addrinfo *ai;
const char *name;
name = va_arg(ap, char *);
ai = va_arg(ap, struct addrinfo *);
memset(&sentinel, 0, sizeof(sentinel));
cur = &sentinel;
if ((ai->ai_family == AF_UNSPEC) || (ai->ai_family == AF_INET6))
aiforaf(name, AF_INET6, ai, &cur);
if ((ai->ai_family == AF_UNSPEC) || (ai->ai_family == AF_INET))

View File

@ -942,7 +942,8 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd)
*inboundStr = NULL, *outboundStr = NULL, *alias = NULL;
const char *sourceModeStr = NULL;
int sourceMode = -1;
virNetDevBandwidthRate inbound, outbound;
virNetDevBandwidthRate inbound = { 0 };
virNetDevBandwidthRate outbound = { 0 };
virDomainNetType typ;
int ret;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
@ -990,7 +991,6 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd)
}
if (inboundStr) {
memset(&inbound, 0, sizeof(inbound));
if (virshParseRateStr(ctl, inboundStr, &inbound) < 0)
return false;
if (!inbound.average && !inbound.floor) {
@ -999,7 +999,6 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd)
}
}
if (outboundStr) {
memset(&outbound, 0, sizeof(outbound));
if (virshParseRateStr(ctl, outboundStr, &outbound) < 0)
return false;
if (outbound.average == 0) {
@ -3286,7 +3285,8 @@ cmdDomIftune(vshControl *ctl, const vshCmd *cmd)
bool current = vshCommandOptBool(cmd, "current");
bool config = vshCommandOptBool(cmd, "config");
bool live = vshCommandOptBool(cmd, "live");
virNetDevBandwidthRate inbound, outbound;
virNetDevBandwidthRate inbound = { 0 };
virNetDevBandwidthRate outbound = { 0 };
size_t i;
VSH_EXCLUSIVE_OPTIONS_VAR(current, live);
@ -3307,9 +3307,6 @@ cmdDomIftune(vshControl *ctl, const vshCmd *cmd)
vshCommandOptStringReq(ctl, cmd, "outbound", &outboundStr) < 0)
goto cleanup;
memset(&inbound, 0, sizeof(inbound));
memset(&outbound, 0, sizeof(outbound));
if (inboundStr) {
if (virshParseRateStr(ctl, inboundStr, &inbound) < 0)
goto cleanup;