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

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



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 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.

Attachment: signature.asc
Description: Digital signature


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