From a6d822cee3d22d763d10ab343a462a4ce4cfa83b Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Wed, 27 Mar 2019 09:19:31 -0500 Subject: [PATCH] Revert "snapshot: Allow NULL to virDomainSnapshotObjGetDef" This reverts commit 6b90a8473875eb34bae27856857cf6561e079089. It turns out gcc -O2 is not happy with it, complaining: /home/pipo/libvirt/src/qemu/qemu_driver.c: In function 'qemuDomainSnapshotCreateXML': /home/pipo/libvirt/src/qemu/qemu_driver.c:15389:26: error: potential null pointer dereference [-Werror=null-dereference] bool memory = snapdef->memory == VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL; ~~~~~~~^~~~~~~~ /home/pipo/libvirt/src/qemu/qemu_driver.c:15389:26: error: potential null pointer dereference [-Werror=null-dereference] In file included from /home/pipo/libvirt/src/util/virbuffer.h:27, from /home/pipo/libvirt/src/conf/capabilities.h:27, from /home/pipo/libvirt/src/conf/domain_conf.h:32, from /home/pipo/libvirt/src/qemu/qemu_agent.h:26, from /home/pipo/libvirt/src/qemu/qemu_driver.c:40: /home/pipo/libvirt/src/util/viralloc.h:125:34: error: potential null pointer dereference [-Werror=null-dereference] # define VIR_ALLOC_N(ptr, count) virAllocN(&(ptr), sizeof(*(ptr)), (count), true, \ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ VIR_FROM_THIS, __FILE__, __FUNCTION__, __LINE__) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /home/pipo/libvirt/src/qemu/qemu_driver.c:15103:9: note: in expansion of macro 'VIR_ALLOC_N' if (VIR_ALLOC_N(ret, snapdef->ndisks) < 0) ^~~~~~~~~~~ /home/pipo/libvirt/src/qemu/qemu_driver.c:15798:45: error: null pointer dereference [-Werror=null-dereference] virDomainSnapshotObjGetDef(snap)->memory == VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL) { ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~ As the patch simplified one or two callers at the risk of making many other callers now candidates to trigger aggressive compiler warnings, it isn't worth it. Signed-off-by: Eric Blake --- src/conf/snapshot_conf.c | 2 +- src/conf/virdomainsnapshotobjlist.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c index 8e4f3d9410..4ce120451e 100644 --- a/src/conf/snapshot_conf.c +++ b/src/conf/snapshot_conf.c @@ -967,7 +967,7 @@ virDomainSnapshotRedefinePrep(virDomainPtr domain, } other = virDomainSnapshotFindByName(vm->snapshots, def->common.name); - otherdef = virDomainSnapshotObjGetDef(other); + otherdef = other ? virDomainSnapshotObjGetDef(other) : NULL; check_if_stolen = other && otherdef->common.dom; if (virDomainSnapshotRedefineValidate(def, domain->uuid, other, xmlopt, flags) < 0) { diff --git a/src/conf/virdomainsnapshotobjlist.h b/src/conf/virdomainsnapshotobjlist.h index 12b574b4ff..b83f7a4ba9 100644 --- a/src/conf/virdomainsnapshotobjlist.h +++ b/src/conf/virdomainsnapshotobjlist.h @@ -87,7 +87,7 @@ int virDomainListSnapshots(virDomainSnapshotObjListPtr snapshots, static inline virDomainSnapshotDefPtr virDomainSnapshotObjGetDef(virDomainMomentObjPtr obj) { - return obj ? (virDomainSnapshotDefPtr) obj->def : NULL; + return (virDomainSnapshotDefPtr) obj->def; } #endif /* LIBVIRT_VIRDOMAINSNAPSHOTOBJLIST_H */ -- 2.47.2