[PATCH 4/5] render: Silence warnings when building with clang

Jamey Sharp jamey at minilop.net
Sun Apr 24 22:11:19 PDT 2011


On Sat, Apr 23, 2011 at 09:52:38PM -0700, Jeremy Huddleston wrote:
> picture.c:351:37: error: implicit conversion from 'unsigned int' to 'CARD16' (aka 'unsigned short') changes value from 4294967295 to 65535
>       [-Werror,-Wconstant-conversion]
>             pFormats[f].direct.alphaMask = Mask(PICT_FORMAT_A(format));
>                                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~

The macro in question is:

	#define Mask(n) ((n) == 32 ? 0xffffffff : ((1 << (n))-1))

It looks to me like *all* of the uses of this Mask macro assign to
CARD16s, so they'd better never exceed 16-bit masks. Which makes sense
for picture formats; I think the largest formats I've noticed anyone ask
for in X had 10 bits per channel.

Rather than suppressing the warning (which could mask future errors),
I'd be inclined to delete the conditional:

	/* Returns a CARD16 mask, n-bits wide. */
	/*@ requires 0 <= n <= 16 */
	#define Mask(n) ((1 << (n)) - 1)

I assume clang won't warn then. Paranoia might suggest also adding some
kind of check to verify that (n) never exceeds 16, but meh.

Jamey
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://lists.x.org/archives/xorg-devel/attachments/20110424/ed582a01/attachment.pgp>


More information about the xorg-devel mailing list