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

From
Andy Shevchenko <hidden>
Date
2012-07-05 08:02:38
Also in
lkml
Reply to
Joe Perches, 2012-07-04
On Wed, Jul 4, 2012 at 6:09 PM, Joe Perches [off-list ref] wrote:
On Wed, 2012-07-04 at 11:45 +0300, Andy Shevchenko wrote:
quoted
This patch adds a support of the variable width buffer to print it
as a hex string with a delimiter.
quoted
+     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.
quoted
+             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
Thread (31 messages) 31 messages, 9 authors, last reply 2012-09-11
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help