mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-22 03:12:22 +00:00
lib: Prefer sizeof(variable) instead of sizeof(type) in memset
If one of previous commits taught us something, it's that: sizeof(variable) and sizeof(type) are not the same. Especially because for live enough code the type might change (e.g. as we use autoptr more). And since we don't get any warnings when an incorrect length is passed to memset() it is easy to mess up. But with sizeof(variable) instead, it's not as easy. Therefore, switch to using memset(variable, 0, sizeof(*variable)), or its alternatives, depending on level of pointers. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Claudio Fontana <cfontana@suse.de>
This commit is contained in:
parent
4f159d4269
commit
1ca3c339a1
@ -7112,7 +7112,7 @@ qemuMonitorJSONSetIOThread(qemuMonitor *mon,
|
||||
|
||||
#define VIR_IOTHREAD_SET_PROP_UL(propName, propVal) \
|
||||
if (iothreadInfo->set_##propVal) { \
|
||||
memset(&prop, 0, sizeof(qemuMonitorJSONObjectProperty)); \
|
||||
memset(&prop, 0, sizeof(prop)); \
|
||||
prop.type = QEMU_MONITOR_OBJECT_PROPERTY_ULONG; \
|
||||
prop.val.ul = iothreadInfo->propVal; \
|
||||
if (qemuMonitorJSONSetObjectProperty(mon, path, propName, &prop) < 0) \
|
||||
@ -7145,7 +7145,7 @@ qemuMonitorJSONSetIOThread(qemuMonitor *mon,
|
||||
|
||||
#define VIR_IOTHREAD_SET_PROP_INT(propName, propVal) \
|
||||
if (iothreadInfo->set_##propVal) { \
|
||||
memset(&prop, 0, sizeof(qemuMonitorJSONObjectProperty)); \
|
||||
memset(&prop, 0, sizeof(prop)); \
|
||||
prop.type = QEMU_MONITOR_OBJECT_PROPERTY_INT; \
|
||||
prop.val.iv = iothreadInfo->propVal; \
|
||||
if (qemuMonitorJSONSetObjectProperty(mon, path, propName, &prop) < 0) \
|
||||
|
@ -5068,7 +5068,7 @@ qemuProcessGraphicsSetupListen(virQEMUDriver *driver,
|
||||
* *_auto_unix_socket set we should use unix socket as
|
||||
* default instead of tcp listen. */
|
||||
if (useSocket) {
|
||||
memset(glisten, 0, sizeof(virDomainGraphicsListenDef));
|
||||
memset(glisten, 0, sizeof(*glisten));
|
||||
glisten->socket = g_strdup_printf("%s/%s.sock", priv->libDir,
|
||||
type);
|
||||
glisten->fromConfig = true;
|
||||
|
@ -2138,7 +2138,7 @@ remoteDomainGetVcpus(virDomainPtr domain,
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
memset(info, 0, sizeof(virVcpuInfo) * maxinfo);
|
||||
memset(info, 0, sizeof(*info) * maxinfo);
|
||||
memset(cpumaps, 0, maxinfo * maplen);
|
||||
|
||||
for (i = 0; i < ret.info.info_len; ++i) {
|
||||
|
@ -1279,7 +1279,7 @@ storagePoolGetInfo(virStoragePoolPtr pool,
|
||||
if (virStorageBackendForType(def->type) == NULL)
|
||||
goto cleanup;
|
||||
|
||||
memset(info, 0, sizeof(virStoragePoolInfo));
|
||||
memset(info, 0, sizeof(*info));
|
||||
if (virStoragePoolObjIsActive(obj))
|
||||
info->state = VIR_STORAGE_POOL_RUNNING;
|
||||
else
|
||||
|
@ -4826,7 +4826,7 @@ static int testDomainGetDiskErrors(virDomainPtr dom,
|
||||
|
||||
if (errors) {
|
||||
/* sanitize input */
|
||||
memset(errors, 0, sizeof(virDomainDiskError) * nerrors);
|
||||
memset(errors, 0, sizeof(*errors) * nerrors);
|
||||
|
||||
for (i = 0; i < nerrors; i++) {
|
||||
errors[i].disk = g_strdup(vm->def->disks[i]->dst);
|
||||
@ -6878,7 +6878,7 @@ testStoragePoolGetInfo(virStoragePoolPtr pool,
|
||||
return -1;
|
||||
def = virStoragePoolObjGetDef(obj);
|
||||
|
||||
memset(info, 0, sizeof(virStoragePoolInfo));
|
||||
memset(info, 0, sizeof(*info));
|
||||
if (virStoragePoolObjIsActive(obj))
|
||||
info->state = VIR_STORAGE_POOL_RUNNING;
|
||||
else
|
||||
|
Loading…
x
Reference in New Issue
Block a user