[Mesa-dev] [PATCH v2] mesa/main: fix gl_buffer_index enum comparison

Samuel Pitoiset samuel.pitoiset at gmail.com
Mon Jun 5 16:19:23 UTC 2017


Thanks!

Reviewed-by: Samuel Pitoiset <samuel.pitoiset at gmail.com>

On 06/05/2017 04:18 PM, Rob Herring wrote:
> For clang, enums are unsigned by default and gives the following warning:
> 
> external/mesa3d/src/mesa/main/buffers.c:764:21: warning: comparison of constant -1 with expression of type 'gl_buffer_index' is always false [-Wtautological-constant-out-of-range-compare]
>        if (srcBuffer == -1) {
>            ~~~~~~~~~ ^  ~~
> 
> Replace -1 with an enum value to fix this.
> 
> Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>
> Signed-off-by: Rob Herring <robh at kernel.org>
> ---
> v2:
> - Also update read_buffer_enum_to_index() and _ColorReadBufferIndex
> 
>   src/mesa/main/buffers.c     | 8 ++++----
>   src/mesa/main/framebuffer.c | 4 ++--
>   src/mesa/main/mtypes.h      | 3 ++-
>   3 files changed, 8 insertions(+), 7 deletions(-)
> 
> diff --git a/src/mesa/main/buffers.c b/src/mesa/main/buffers.c
> index 7d17ae92de23..d85974afe60d 100644
> --- a/src/mesa/main/buffers.c
> +++ b/src/mesa/main/buffers.c
> @@ -231,7 +231,7 @@ read_buffer_enum_to_index(const struct gl_context *ctx, GLenum buffer)
>            if (buffer >= GL_COLOR_ATTACHMENT8 && buffer <= GL_COLOR_ATTACHMENT31)
>               return BUFFER_COUNT;
>            /* error */
> -         return -1;
> +         return BUFFER_NONE;
>      }
>   }
>   
> @@ -752,16 +752,16 @@ read_buffer(struct gl_context *ctx, struct gl_framebuffer *fb,
>   
>      if (buffer == GL_NONE) {
>         /* This is legal--it means that no buffer should be bound for reading. */
> -      srcBuffer = -1;
> +      srcBuffer = BUFFER_NONE;
>      }
>      else {
>         /* general case / window-system framebuffer */
>         if (_mesa_is_gles3(ctx) && !is_legal_es3_readbuffer_enum(buffer))
> -         srcBuffer = -1;
> +         srcBuffer = BUFFER_NONE;
>         else
>            srcBuffer = read_buffer_enum_to_index(ctx, buffer);
>   
> -      if (srcBuffer == -1) {
> +      if (srcBuffer == BUFFER_NONE) {
>            _mesa_error(ctx, GL_INVALID_ENUM,
>                        "%s(invalid buffer %s)", caller,
>                        _mesa_enum_to_string(buffer));
> diff --git a/src/mesa/main/framebuffer.c b/src/mesa/main/framebuffer.c
> index 5069d373948f..8e8f19ab3b85 100644
> --- a/src/mesa/main/framebuffer.c
> +++ b/src/mesa/main/framebuffer.c
> @@ -251,7 +251,7 @@ _mesa_reference_framebuffer_(struct gl_framebuffer **ptr,
>         oldFb->RefCount--;
>         deleteFlag = (oldFb->RefCount == 0);
>         mtx_unlock(&oldFb->Mutex);
> -
> +
>         if (deleteFlag)
>            oldFb->Delete(oldFb);
>   
> @@ -624,7 +624,7 @@ static void
>   update_color_read_buffer(struct gl_context *ctx, struct gl_framebuffer *fb)
>   {
>      (void) ctx;
> -   if (fb->_ColorReadBufferIndex == -1 ||
> +   if (fb->_ColorReadBufferIndex == BUFFER_NONE ||
>          fb->DeletePending ||
>          fb->Width == 0 ||
>          fb->Height == 0) {
> diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
> index 9ef1b18ea5b4..c77c2ec54e5e 100644
> --- a/src/mesa/main/mtypes.h
> +++ b/src/mesa/main/mtypes.h
> @@ -144,7 +144,8 @@ typedef enum
>      BUFFER_COLOR5,
>      BUFFER_COLOR6,
>      BUFFER_COLOR7,
> -   BUFFER_COUNT
> +   BUFFER_COUNT,
> +   BUFFER_NONE = -1,
>   } gl_buffer_index;
>   
>   /**
> 


More information about the mesa-dev mailing list