[PATCH] staging: speakup: kobjects.c: fix char argument to %02x

Joe Perches joe at perches.com
Sun Dec 6 00:28:29 UTC 2015


On Sun, 2015-12-06 at 01:21 +0100, Rasmus Villemoes wrote:
> On Sun, Dec 06 2015, Joe Perches <joe at perches.com> wrote:
> 
> > On Sun, 2015-12-06 at 01:05 +0100, Rasmus Villemoes wrote:
> > > If char is signed and ch happens to be negative, printing ch with
> > > "%02x" will not do as intended (when ch is -19, one will get
> > > "ffffffed"). Fix that by masking with 0xff.
> > 
> > I presume there are a lot of these in the kernel.
> > Did you use a tool to find this or just inspection?
> 
> Initially I just used coccinelle, for the most obvious candidates
> (with
> --include-headers-for-types):
> 
> @r depends on !patch@
> char c;
> @@
> * \( sprintf \| snprintf \| scnprintf \) (..., c, ...)
> 
> That gives lots of false positives (arguments to %c), but it's not
> too
> bad piping to less, searching for "%[0.]2[xX]", and then checking
> manually.
> 
> I'm now doing a much wider range of printf functions, but it's really
> past my bedtime, so feel free to pick up the ball :-)
> 

Thanks, but no thanks.  It's your ball.  Enjoy...

You might consider looking for s8 and s16 emitted as %u too.



More information about the devel mailing list