Re: [PATCH spice-common 3/3] SpiceROP: Do not compare to constant

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

 



On Sat, May 07, 2016 at 09:38:07AM -0400, Frediano Ziglio wrote:
> > 
> > Silence compile-time warning with clang:
> >  comparison of constant 16 with expression of type 'SpiceROP' is always
> >  true [-Wtautological-constant-out-of-range-compare]
> > ---
> >  common/pixman_utils.c | 4 ++--
> >  common/pixman_utils.h | 3 ++-
> >  2 files changed, 4 insertions(+), 3 deletions(-)
> > 
> > diff --git a/common/pixman_utils.c b/common/pixman_utils.c
> > index 81806c9..5a03ff2 100644
> > --- a/common/pixman_utils.c
> > +++ b/common/pixman_utils.c
> > @@ -311,7 +311,7 @@ void spice_pixman_fill_rect_rop(pixman_image_t *dest,
> >      spice_assert(height > 0);
> >      spice_assert(x + width <= pixman_image_get_width(dest));
> >      spice_assert(y + height <= pixman_image_get_height(dest));
> > -    spice_assert(rop < 16);
> > +    spice_assert(rop < SPICE_ROP_END);
> >  
> >      if (depth == 8) {
> >          solid_rop_8_func_t rop_func = solid_rops_8[rop];
> 
> What?
> Honestly I think either we are enabling too much warning or clang is wrong!
> This is C, not C++, enumerators can be different quite easily so there is no
> reason to assume that (I would open a bug to clang if this is inside -Wall).

If you read the C standard literally, enum SpiceROP rop can never have
16 as a value, as 16 is not one of the values listed in enum SpiceROP
definition. Thus, 'rop' being outside of the [0, 15] range is undefined
behaviour/should never happen. So I would not say clang is wrong. But
maybe a bit overzealous with the warning ;)

Christophe

Attachment: signature.asc
Description: PGP signature

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/spice-devel

[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]