[Mesa-dev] [PATCH 12/20] intel: Silence "intel/intel_fbo.h:105:4: warning: comparison of unsigned expression < 0 is always false"

Eric Anholt eric at anholt.net
Thu Sep 8 13:16:21 PDT 2011


On Mon, 29 Aug 2011 14:59:02 -0700, "Ian Romanick" <idr at freedesktop.org> wrote:
> From: Ian Romanick <ian.d.romanick at intel.com>
> 
> The test was of an enum, attIndex, which should be unsigned.  The
> explicit check for < 0 was replaced with a cast to unsigned in an
> assertion that attIndex is less than the size of the array it will be
> used to index.
>
> ---
>  src/mesa/drivers/dri/intel/intel_fbo.h |    6 +++---
>  1 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/src/mesa/drivers/dri/intel/intel_fbo.h b/src/mesa/drivers/dri/intel/intel_fbo.h
> index 2487994..d8fc1a5 100644
> --- a/src/mesa/drivers/dri/intel/intel_fbo.h
> +++ b/src/mesa/drivers/dri/intel/intel_fbo.h
> @@ -29,6 +29,8 @@
>  #define INTEL_FBO_H
>  
>  #include <stdbool.h>
> +#include <assert.h>
> +#include "main/compiler.h"
>  #include "main/formats.h"
>  #include "intel_screen.h"
>  
> @@ -101,9 +103,7 @@ intel_get_renderbuffer(struct gl_framebuffer *fb, gl_buffer_index attIndex)
>     struct gl_renderbuffer *rb;
>     struct intel_renderbuffer *irb;
>  
> -   /* XXX: Who passes -1 to intel_get_renderbuffer? */
> -   if (attIndex < 0)
> -      return NULL;
> +   assert((unsigned)attIndex < Elements(fb->Attachment));

Majority of uses in the driver is the kernel-style ARRAY_SIZE() instead
of Elements(), but this is definitely better either way.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20110908/903e5535/attachment.pgp>


More information about the mesa-dev mailing list