[Piglit] [PATCH] teximage-colors: fix divide by zero issue

Brian Paul brianp at vmware.com
Wed Sep 17 10:17:40 PDT 2014


Ugh, I see this has already been covered today.  I don't have a strong 
preference for which fix is used.

-Brian

On 09/17/2014 11:14 AM, Brian Paul wrote:
> Not exactly sure why, but the max = ~(~0ul << bits) assignment resulted
> in max=0 when bits==32 with MinGW.  This caused us to do a divide by zero
> and many of the tests failed.
>
> Special-case the 32-bit case and change the arithmetic to be a little
> simpler (to me at least).  Change sn_to_float() to be similar.
> ---
>   tests/texturing/teximage-colors.c |   11 +++++++++--
>   1 file changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/tests/texturing/teximage-colors.c b/tests/texturing/teximage-colors.c
> index 815ef4d..b350b99 100644
> --- a/tests/texturing/teximage-colors.c
> +++ b/tests/texturing/teximage-colors.c
> @@ -189,14 +189,21 @@ valid_combination(GLenum format, GLenum type)
>   static float
>   un_to_float(unsigned char bits, unsigned int color)
>   {
> -	unsigned int max = ~(~0ul << bits);
> +	unsigned int max;
> +	if (bits == 32) {
> +		max = 0xffffffffU;
> +	}
> +	else {
> +		assert(bits < 32);
> +		max = (1 << bits) - 1;
> +	}
>   	return (float)color / (float)max;
>   }
>
>   static float
>   sn_to_float(unsigned char bits, int color)
>   {
> -	int max = ~(~0 << (bits-1));
> +	int max = (1 << (bits - 1)) - 1;
>   	if (color < -max)
>   		color = -max;
>   	return (float)color / (float)max;
>



More information about the Piglit mailing list