Re: [PATCHv3 2/3] lib: printf: append support of '%*ph[CDN]'

From: Andy Shevchenko
Date: Thu Jul 05 2012 - 04:02:31 EST


On Wed, Jul 4, 2012 at 6:09 PM, Joe Perches <joe@xxxxxxxxxxx> wrote:
> On Wed, 2012-07-04 at 11:45 +0300, Andy Shevchenko wrote:
>> This patch adds a support of the variable width buffer to print it
>> as a hex string with a delimiter.

>> + Â Â if (spec.field_width <= 0)
>> + Â Â Â Â Â Â /* nothing to print */
>> + Â Â Â Â Â Â return buf;
>
> It may be better to default to a 1 and add
>
> Â Â Â Â if (addr == ZERO_OR_NULL_PTR)
>
> to avoid dereferencing a NULL or a pointer
> to a zero length object.
Good point.

>> + Â Â Â Â Â Â for (p = hex_str; *p != '\0'; p++) {
>> + Â Â Â Â Â Â Â Â Â Â if (buf < end)
>> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â *buf = *p;
>> + Â Â Â Â Â Â Â Â Â Â ++buf;
>> + Â Â Â Â Â Â }
>
> why not just directly write to *buf as long as buf < end?
buf < end - 1, otherwise correct.
And yes, it eliminates hex_str array as well.

--
With Best Regards,
Andy Shevchenko
--
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/