]> xenbits.xensource.com Git - xen.git/commit
xen/x86: Fix build with clang following c/s 4fa0105
authorAndrew Cooper <andrew.cooper3@citrix.com>
Thu, 8 Sep 2016 17:52:46 +0000 (18:52 +0100)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Fri, 9 Sep 2016 14:31:01 +0000 (15:31 +0100)
commit4c47c47938ea24c73d9459f9f0b6923513772b5d
tree8bbd5aaaeb8c1bd5faa2e6dc886db8cd477cca2f
parent26ea2cce0d3d25974eea3c643ce2081adfa2a69c
xen/x86: Fix build with clang following c/s 4fa0105

https://travis-ci.org/xen-project/xen/jobs/158494027#L2344

Clang complains:

  emulate.c:2016:14: error: comparison of unsigned enum expression < 0
  is always false [-Werror,-Wtautological-compare]
      if ( seg < 0 || seg >= ARRAY_SIZE(hvmemul_ctxt->seg_reg) )
           ~~~ ^ ~

Clang is wrong to raise a warning like this.  The signed-ness of an enum is
implementation defined in C, and robust code must not assume the choices made
by the compiler.

In this case, dropping the < 0 check creates a latent bug which would result
in an array underflow when compiled with a compiler which chooses a signed
enum.

Work around the bug by explicitly pulling seg into an unsigned integer, and
only perform the upper bounds check.

No functional change.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: George Dunlap <george.dunlap@citrix.com>
xen/arch/x86/hvm/emulate.c
xen/arch/x86/mm/shadow/common.c