util/format: Fix clamping to 32bit integers.
authorJosé Fonseca <jfonseca@vmware.com>
Fri, 7 Nov 2014 21:20:25 +0000 (21:20 +0000)
committerJosé Fonseca <jfonseca@vmware.com>
Sat, 8 Nov 2014 10:32:39 +0000 (10:32 +0000)
commitb238c756da5b8c54437e58c2878ecae7467079eb
tree146327aeb91ac81e88e0f06f52e46d77b3026399
parentd268eac3a9c81febc5efcae7fe6854045bfc5144
util/format: Fix clamping to 32bit integers.

Use clamping constants that guarantee no integer overflows.

As spotted by Chris Forbes.

This causes the code to change as:

-         value |= (uint32_t)CLAMP(src[0], 0.0f, 4294967295.0f);
+         value |= (uint32_t)CLAMP(src[0], 0.0f, 4294967040.0f);

-         value |= (uint32_t)((int32_t)CLAMP(src[0], -2147483648.0f, 2147483647.0f));
+         value |= (uint32_t)((int32_t)CLAMP(src[0], -2147483648.0f, 2147483520.0f));

Reviewed-by: Roland Scheidegger <sroland@vmware.com>
src/gallium/auxiliary/util/u_format_pack.py