From a0dc4521726140220c524e22007e4b20f83ed973 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Wed, 7 Apr 2010 17:27:50 +0200 Subject: [PATCH] qemudDomainAttachSCSIDisk: avoid FP NULL-ptr-deref from clang * src/qemu/qemu_driver.c (qemudDomainAttachSCSIDisk): Initialize "cont" to NULL, so clang knows it's set. Add an sa_assert so it knows it's non-NULL when dereferenced. --- src/qemu/qemu_driver.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index df1d4355b1..f5cf1f1538 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -6851,7 +6851,7 @@ static int qemudDomainAttachSCSIDisk(struct qemud_driver *driver, { int i; qemuDomainObjPrivatePtr priv = vm->privateData; - virDomainControllerDefPtr cont; + virDomainControllerDefPtr cont = NULL; char *drivestr = NULL; char *devstr = NULL; int ret = -1; @@ -6894,6 +6894,11 @@ static int qemudDomainAttachSCSIDisk(struct qemud_driver *driver, goto error; } + /* Tell clang that "cont" is non-NULL. + This is because disk->info.addr.driver.controller is unsigned, + and hence the above loop must iterate at least once. */ + sa_assert (cont); + if (cont->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI) { qemuReportError(VIR_ERR_INTERNAL_ERROR, _("SCSI controller %d was missing its PCI address"), cont->idx); -- GitLab