Re: [PATCH RESEND 2/3] kmsg: export printk records to the /dev/kmsg interface

From: Linus Torvalds
Date: Thu May 10 2012 - 12:05:28 EST


On Thu, May 10, 2012 at 4:45 AM, Dan Carpenter <dan.carpenter@xxxxxxxxxx> wrote:
> On Thu, May 03, 2012 at 02:29:41AM +0200, Kay Sievers wrote:
>> +     /* escape non-printable characters */
>> +     for (i = 0; i < msg->text_len; i++) {
>> +             char c = log_text(msg)[i];
>> +
>> +             if (c < ' ' || c >= 128)
>
> Signed char type is never larger than 127.

You don't know that it's signed.

The sign of "char" is implementation-defined, and there are indeed
architectures that Linux supports where it is unsigned (I think ARM is
one example).

So that comparison against 128 is actually required.

Or, better yet, the code should make 'c' *explicitly* signed (or
unsigned) so that this particular C language definition oddity is
avoided entirely.

Linus
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/