lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Mon, 30 Nov 2020 16:39:04 -0800
From:   Stephen Hemminger <stephen@...workplumber.org>
To:     Petr Machata <me@...chata.org>
Cc:     netdev@...r.kernel.org, dsahern@...il.com, Po.Liu@....com,
        toke@...e.dk, dave.taht@...il.com, edumazet@...gle.com,
        tahiliani@...k.edu.in, vtlam@...gle.com, leon@...nel.org
Subject: Re: [PATCH iproute2-next 3/6] lib: Move sprint_size() from tc here,
 add print_size()

On Mon, 30 Nov 2020 23:59:39 +0100
Petr Machata <me@...chata.org> wrote:

> +char *sprint_size(__u32 sz, char *buf)
> +{
> +	size_t len = SPRINT_BSIZE - 1;
> +	double tmp = sz;
> +
> +	if (sz >= 1024*1024 && fabs(1024*1024*rint(tmp/(1024*1024)) - sz) < 1024)
> +		snprintf(buf, len, "%gMb", rint(tmp/(1024*1024)));
> +	else if (sz >= 1024 && fabs(1024*rint(tmp/1024) - sz) < 16)
> +		snprintf(buf, len, "%gKb", rint(tmp/1024));
> +	else
> +		snprintf(buf, len, "%ub", sz);
> +
> +	return buf;
> +}

Add some whitespace here and maybe some constants like mb and kb?

Also, instead of magic SPRINT_BSIZE, why not take a len param (and name it snprint_size)?

Yes when you copy/paste code it is good time to get it back to current style
standards.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ