lkml.org 
[lkml]   [2018]   [Feb]   [13]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: [PATCH] vsprintf: replace space with readable '=' before crng is ready
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);

Rasmus

\
 
 \ /
  Last update: 2018-02-13 08:18    [W:0.035 / U:0.808 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site