[PATCH 3/6] ppc64Compute: Avoid false positive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



There is no way for a guest_model to be NULL. But gcc fails to
see that.

cpu/cpu_ppc64.c: In function 'ppc64Compute':
cpu/cpu_ppc64.c:620:27: error: potential null pointer dereference [-Werror=null-dereference]
     if (STRNEQ(guest_model->name, host_model->name)) {
                ~~~~~~~~~~~^~~
cpu/cpu_ppc64.c:620:9: note: in expansion of macro 'STRNEQ'
     if (STRNEQ(guest_model->name, host_model->name)) {
         ^~~~~~
cc1: all warnings being treated as errors

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 src/cpu/cpu_ppc64.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/src/cpu/cpu_ppc64.c b/src/cpu/cpu_ppc64.c
index 799fb8e..cca051b 100644
--- a/src/cpu/cpu_ppc64.c
+++ b/src/cpu/cpu_ppc64.c
@@ -586,7 +586,7 @@ ppc64Compute(virCPUDefPtr host,
     if (cpu->type == VIR_CPU_TYPE_GUEST) {
         /* Guest CPU information */
         virCPUCompareResult tmp;
-        switch (cpu->mode) {
+        switch ((virCPUMode) cpu->mode) {
         case VIR_CPU_MODE_HOST_MODEL:
             /* host-model only:
              * we need to take compatibility modes into account */
@@ -610,6 +610,10 @@ ppc64Compute(virCPUDefPtr host,
             if (!(guest_model = ppc64ModelFromCPU(cpu, map)))
                 goto cleanup;
             break;
+
+        case VIR_CPU_MODE_LAST:
+            /* nada */
+            break;
         }
     } else {
         /* Other host CPU information */
@@ -617,6 +621,12 @@ ppc64Compute(virCPUDefPtr host,
             goto cleanup;
     }
 
+    if (!guest_model) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("guest_model not set"));
+        goto cleanup;
+    }
+
     if (STRNEQ(guest_model->name, host_model->name)) {
         VIR_DEBUG("host CPU model does not match required CPU model %s",
                   guest_model->name);
-- 
2.8.3

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]