summaryrefslogtreecommitdiffstats
path: root/lib/libutil
diff options
context:
space:
mode:
authorotto <otto@openbsd.org>2005-03-08 15:35:35 +0000
committerotto <otto@openbsd.org>2005-03-08 15:35:35 +0000
commit4143d7fd694b76eaa7476170ae46b31bb96b1f68 (patch)
tree6a48c688d566b6d96564e594e41b6bba6f7739ad /lib/libutil
parentfrom the "shut the fuck up, ntpd" department: (diff)
downloadwireguard-openbsd-4143d7fd694b76eaa7476170ae46b31bb96b1f68.tar.xz
wireguard-openbsd-4143d7fd694b76eaa7476170ae46b31bb96b1f68.zip
Fix sizing of fraction. ok tom@ deraadt@
Diffstat (limited to 'lib/libutil')
-rw-r--r--lib/libutil/fmt_scaled.c13
1 files changed, 4 insertions, 9 deletions
diff --git a/lib/libutil/fmt_scaled.c b/lib/libutil/fmt_scaled.c
index c868b4d321f..81edf9a03bb 100644
--- a/lib/libutil/fmt_scaled.c
+++ b/lib/libutil/fmt_scaled.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fmt_scaled.c,v 1.4 2004/09/16 10:56:35 otto Exp $ */
+/* $OpenBSD: fmt_scaled.c,v 1.5 2005/03/08 15:35:35 otto Exp $ */
/*
* Copyright (c) 2001, 2002, 2003 Ian F. Darwin. All rights reserved.
@@ -37,7 +37,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static const char ident[] = "$OpenBSD: fmt_scaled.c,v 1.4 2004/09/16 10:56:35 otto Exp $";
+static const char ident[] = "$OpenBSD: fmt_scaled.c,v 1.5 2005/03/08 15:35:35 otto Exp $";
#endif /* LIBC_SCCS and not lint */
#include <stdio.h>
@@ -222,17 +222,12 @@ fmt_scaled(long long number, char *result)
unit = units[i];
fract = (i == 0) ? 0 : abval % scale_factors[i];
number /= scale_factors[i];
+ if (i > 0)
+ fract /= scale_factors[i - 1];
break;
}
}
- /* scale fraction to one digit (by rounding) - thnx pjanzen */
- for (i = SCALE_LENGTH-1; i > 0; i--) {
- if (fract >= scale_factors[i]) {
- fract /= scale_factors[i];
- break;
- }
- }
fract = (10 * fract + 512) / 1024;
/* if the result would be >= 10, round main number */
if (fract == 10) {