From: "Yang, Shunyong" <shunyong.yang@hxt-semitech.com>
To: "linux@rasmusvillemoes.dk" <linux@rasmusvillemoes.dk>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"andriy.shevchenko@linux.intel.com"
<andriy.shevchenko@linux.intel.com>,
"Zheng, Joey" <yu.zheng@hxt-semitech.com>,
"me@tobin.cc" <me@tobin.cc>
Subject: Re: [PATCH] vsprintf: replace space with readable '=' before crng is ready
Date: Tue, 13 Feb 2018 07:57:50 +0000 [thread overview]
Message-ID: <1518508670.3326.6.camel@hxt-semitech.com> (raw)
In-Reply-To: <CAKwiHFiLQjFc3x9Q9=GEgnuiDPH_aBf7P1-=wPB7WtTo2ExDaA@mail.gmail.com>
Hi, Rasmus,
On Tue, 2018-02-13 at 08:16 +0100, Rasmus Villemoes wrote:
> On 13 February 2018 at 07:20, Shunyong Yang
> <shunyong.yang@hxt-semitech.com> wrote:
>
> >
> >
> > This patch replaces space with readable "=" when output needs
> > padding.
> > Following is the output after applying the patch,
> >
> > Suggested-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
> >
> > if (unlikely(!have_filled_random_ptr_key)) {
> > + char *ptrval_str = "(ptrval)";
> > + char str[default_width + 1];
> > + int len = strlen(ptrval_str);
> > +
> > + if (default_width > len) {
> > + int pos;
> > +
> > + pos = (default_width - len) / 2;
> > + memset(str, '=', default_width);
> > + memcpy(str + pos + 1, ptrval_str + 1, len -
> > 2);
> > + str[0] = '(';
> > + str[default_width - 1] = ')';
> > + str[default_width] = 0;
> > + ptrval_str = str;
> > + }
> > +
> I'm sorry, but that's way too convoluted.
>
> >
> > spec.field_width = default_width;
> > /* string length must be less than default_width */
> > - return string(buf, end, "(ptrval)", spec);
> > + return string(buf, end, ptrval_str, spec);
> > }
> I was thinking of just doing something like
>
> - return string(buf, end, "(ptrval)", spec);
> + return string(buf, end, sizeof(void *) == 8 ?
> "(====ptrval====)" : "(ptrval)", spec);
>
Thanks a lot! It's more straightforward considering 32/64-bit system.
Thanks.
Shunyong.
next prev parent reply other threads:[~2018-02-13 7:58 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-13 6:20 [PATCH] vsprintf: replace space with readable '=' before crng is ready Shunyong Yang
2018-02-13 7:16 ` Rasmus Villemoes
2018-02-13 7:57 ` Yang, Shunyong [this message]
2018-02-13 19:46 ` Tobin C. Harding
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1518508670.3326.6.camel@hxt-semitech.com \
--to=shunyong.yang@hxt-semitech.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@rasmusvillemoes.dk \
--cc=me@tobin.cc \
--cc=yu.zheng@hxt-semitech.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox