On 3/27/19 5:10 AM, Eric Blake wrote:
Doing so can simplify some callers.
Signed-off-by: Eric Blake <eblake(a)redhat.com>
---
src/conf/virdomainsnapshotobjlist.h | 2 +-
src/conf/snapshot_conf.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
Peter reported that at -O2, this makes gcc unhappy. I'll probably just
revert this one (the coding convenience savings for one or two callers
do not outweigh the potential NULL dereference logic to be checked at
all other callers).
/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) {
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~
diff --git a/src/conf/virdomainsnapshotobjlist.h b/src/conf/virdomainsnapshotobjlist.h
index b83f7a4ba9..12b574b4ff 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 (virDomainSnapshotDefPtr) obj->def;
+ return obj ? (virDomainSnapshotDefPtr) obj->def : NULL;
}
#endif /* LIBVIRT_VIRDOMAINSNAPSHOTOBJLIST_H */
diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c
index 4ce120451e..8e4f3d9410 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 = other ? virDomainSnapshotObjGetDef(other) : NULL;
+ otherdef = virDomainSnapshotObjGetDef(other);
check_if_stolen = other && otherdef->common.dom;
if (virDomainSnapshotRedefineValidate(def, domain->uuid, other, xmlopt,
flags) < 0) {
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3226
Virtualization:
qemu.org |
libvirt.org