[Piglit] [PATCH piglit] teximage-color: Use UINT64_C() instead of ul for a 64-bit constant

Neil Roberts neil at linux.intel.com
Wed Sep 17 07:53:00 PDT 2014


The un_to_float function was trying to get the maximum value given a
number of bits by shifting ~0ul by the number of bits. For the
GL_UNSIGNED_INT type this function was also being used to get a
maximum value for a 32-bit quantity. However on a 32-bit build this
would mean that it is shifting a 32-bit integer (unsigned long is
32-bit) by 32 bits. The C spec leaves it undefined what happens if you
do a shift that is greater than the number of bits in the type. GCC
takes advantage of that to make the shift a no-op so the maximum was
ending up as zero and the test fails. This patch makes it use
UINT64_C(0) instead of ~0ul to make sure the constant is a 64-bit
value.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=83695
---
 tests/texturing/teximage-colors.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/texturing/teximage-colors.c b/tests/texturing/teximage-colors.c
index 815ef4d..08a3869 100644
--- a/tests/texturing/teximage-colors.c
+++ b/tests/texturing/teximage-colors.c
@@ -189,7 +189,7 @@ 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 = ~(~UINT64_C(0) << bits);
 	return (float)color / (float)max;
 }
 
-- 
1.9.3



More information about the Piglit mailing list