[Mesa-dev] [PATCH 3/3] mesa: Fix tautological compare

Ian Romanick idr at freedesktop.org
Wed Feb 28 06:08:04 UTC 2018


On 02/27/2018 07:38 PM, Brian Paul wrote:
> On 02/27/2018 06:07 PM, Ian Romanick wrote:
>> From: Ian Romanick <ian.d.romanick at intel.com>
>>
>> _BaseFormat is GLenum16, but it is compared with an integer -1.  Even if
>> _mesa_base_tex_format returned -1, it becomes 0xffff, and the
>> comparison, after type promotion, will always fail.  Fix this by
>> explicitly casting both to GLenum16.  This should be more future proof
>> that casting just the -1.
> 
> "than"
> 
> Series is, Reviewed-by: Brian Paul <brianp at vmware.com>
> 
> How about we change _mesa_base_tex_format() to return GL_INVALID_ENUM
> instead of -1?  Or, even 0 like _mesa_base_fbo_format()?

I considered that.  It would be a much more invasive change, and I was
feeling lazy. :) There are a lot of callers.  Most either test the value
directly as 'if (_mesa_base_tex_format(...) < 0)' or assign the value to
a GLenum.  I can still do that...

> -Brian
> 
>> CID: 1429517
>> Fixes: ca721b3 ("mesa: use GLenum16 in a few more places")
>> Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
>> ---
>>   src/mesa/main/teximage.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/src/mesa/main/teximage.c b/src/mesa/main/teximage.c
>> index 35ed875..1d7bff5 100644
>> --- a/src/mesa/main/teximage.c
>> +++ b/src/mesa/main/teximage.c
>> @@ -853,7 +853,7 @@ init_teximage_fields_ms(struct gl_context *ctx,
>>        target = img->TexObject->Target;
>>      img->_BaseFormat = _mesa_base_tex_format( ctx, internalFormat );
>> -   assert(img->_BaseFormat != -1);
>> +   assert((GLenum16) img->_BaseFormat != (GLenum16) -1);
>>      img->InternalFormat = internalFormat;
>>      img->Border = border;
>>      img->Width = width;


More information about the mesa-dev mailing list