[libvirt] [PATCH 3/6] ppc64Compute: Avoid false positive

Peter Krempa pkrempa at redhat.com
Tue May 31 10:59:55 UTC 2016


On Tue, May 31, 2016 at 12:33:28 +0200, Michal Privoznik wrote:
> 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 at redhat.com>
> ---
>  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 */

Drop this comment.

> +            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;
> +    }

This is dead code since everything before checked that model was set. If
you want to add this check here, then remove all the checks above and
make it just jump to cleanup without reporting error. Since it's
impossible to happen.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20160531/c9d5f908/attachment-0001.sig>


More information about the libvir-list mailing list