[PATCH] input: Fix format string for verify_internal_event

Jeremy Huddleston jeremyhu at apple.com
Mon May 16 08:39:56 PDT 2011

On May 16, 2011, at 01:13, Mark Kettenis wrote:

> On Sat, May 14, 2011 at 04:31:10PM -0700, Jeremy Huddleston wrote:
>> inpututils.c:577:25: warning: conversion specifies type 'unsigned short' but the argument has type 'unsigned char' [-Wformat,Format String Issue]
>>            ErrorF("%02hx ", *data);
>>                    ~~~~^    ~~~~~
>>                    %02hhx
>> 1 warning generated.
> While the fix isn't wrong, it's odd that clang complains about this.
> Since ErrorF is a varargs function, *data will be promoted to int, so
> while printing it with %02hx is a bit odd, it is perfectly legal C.
> Because of the integer promotion, I would actually simply use %02x
> here, since I think the h and hh length modifiers are a bit obscure.
> Would clang complain about using %02x as well?

Yes, and I believe gcc will complain about it as well if you specify a strict enough -Wformat.  The warning is there to ensure that you know what you are doing.  Yes, functionally they probably result in the bits output, but eliminating warnings helps the important ones stand out more.

More information about the xorg-devel mailing list