Return-path: Received: from mail-ee0-f46.google.com ([74.125.83.46]:42798 "EHLO mail-ee0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755392Ab2GEICb convert rfc822-to-8bit (ORCPT ); Thu, 5 Jul 2012 04:02:31 -0400 MIME-Version: 1.0 In-Reply-To: <1341414588.3627.42.camel@joe2Laptop> References: <1341341280.2012.3.camel@joe2Laptop> <1341391552-4842-1-git-send-email-andriy.shevchenko@linux.intel.com> <1341391552-4842-2-git-send-email-andriy.shevchenko@linux.intel.com> <1341414588.3627.42.camel@joe2Laptop> Date: Thu, 5 Jul 2012 11:02:28 +0300 Message-ID: (sfid-20120705_100330_890311_01E02878) Subject: Re: [PATCHv3 2/3] lib: printf: append support of '%*ph[CDN]' From: Andy Shevchenko To: Joe Perches Cc: Andy Shevchenko , Andrew Morton , proski@gnu.org, Andrei Emeltchenko , linux-wireless@vger.kernel.org, LKML , Larry Finger Content-Type: text/plain; charset=UTF-8 Sender: linux-wireless-owner@vger.kernel.org List-ID: On Wed, Jul 4, 2012 at 6:09 PM, Joe Perches 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