Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
SUSE:SLE-12-SP2:GA
mdadm.5365
0041-util-remove-rounding-error-where-reporting...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 0041-util-remove-rounding-error-where-reporting-human-siz.patch of Package mdadm.5365
From 93d3bd3b28486ae3f933b3f94c81d27565d5e89e Mon Sep 17 00:00:00 2001 From: NeilBrown <neilb@suse.de> Date: Thu, 18 Dec 2014 16:48:15 +1100 Subject: [PATCH 051/359] util: remove rounding error where reporting "human sizes". References: bsc#1081910 The division 1<<20 / 200 is not exact, so dividing by this to convert bytes into half-megs is wrong and results in incorrect output. As we are doing "long long" arithmetic, there is no risk of an overflow until we reach 64 petabytes. So change to * 200 / (1<<20). Reported-by: Jan Echternach <jan@goneko.de> Resolved-debian-bug: 763917 Url: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=763917 Signed-off-by: NeilBrown <neilb@suse.de> Signed-off-by: Coly Li <colyli@suse.de> --- util.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/util.c b/util.c index 37c6e0d..89f6b0f 100644 --- a/util.c +++ b/util.c @@ -671,13 +671,13 @@ char *human_size(long long bytes) if (bytes < 5000*1024) buf[0] = 0; else if (bytes < 2*1024LL*1024LL*1024LL) { - long cMiB = (bytes / ( (1LL<<20) / 200LL ) +1) /2; + long cMiB = (bytes * 200LL / (1LL<<20) + 1) / 2; long cMB = (bytes / ( 1000000LL / 200LL ) +1) /2; snprintf(buf, sizeof(buf), " (%ld.%02ld MiB %ld.%02ld MB)", cMiB/100 , cMiB % 100, cMB/100, cMB % 100); } else { - long cGiB = (bytes / ( (1LL<<30) / 200LL ) +1) /2; + long cGiB = (bytes * 200LL / (1LL<<30) +1) / 2; long cGB = (bytes / (1000000000LL/200LL ) +1) /2; snprintf(buf, sizeof(buf), " (%ld.%02ld GiB %ld.%02ld GB)", cGiB/100 , cGiB % 100, @@ -706,11 +706,11 @@ char *human_size_brief(long long bytes, int prefix) buf[0] = 0; else if (prefix == IEC) { if (bytes < 2*1024LL*1024LL*1024LL) { - long cMiB = (bytes / ( (1LL<<20) / 200LL ) +1) /2; + long cMiB = (bytes * 200LL / (1LL<<20) +1) /2; snprintf(buf, sizeof(buf), "%ld.%02ldMiB", cMiB/100 , cMiB % 100); } else { - long cGiB = (bytes / ( (1LL<<30) / 200LL ) +1) /2; + long cGiB = (bytes * 200LL / (1LL<<30) +1) /2; snprintf(buf, sizeof(buf), "%ld.%02ldGiB", cGiB/100 , cGiB % 100); } -- 2.16.1
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor