summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDamien Miller <djm@cvs.openbsd.org>2018-05-14 04:39:05 +0000
committerDamien Miller <djm@cvs.openbsd.org>2018-05-14 04:39:05 +0000
commit50dea7aecc6f766e892e6938148dad5c922da2e8 (patch)
tree8aa2ae67a68c92bcece0b0c62f98e65bb7f3a505 /lib
parentdf17499cf576bf40b00001b870354c1556c301bb (diff)
constrain fractional part to [0-9] (less confusing to static analysis); ok ian@
Diffstat (limited to 'lib')
-rw-r--r--lib/libutil/fmt_scaled.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/lib/libutil/fmt_scaled.c b/lib/libutil/fmt_scaled.c
index 7a4dee2d04b..f9c8f65c865 100644
--- a/lib/libutil/fmt_scaled.c
+++ b/lib/libutil/fmt_scaled.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fmt_scaled.c,v 1.16 2017/03/16 02:40:46 dtucker Exp $ */
+/* $OpenBSD: fmt_scaled.c,v 1.17 2018/05/14 04:39:04 djm Exp $ */
/*
* Copyright (c) 2001, 2002, 2003 Ian F. Darwin. All rights reserved.
@@ -242,12 +242,15 @@ fmt_scaled(long long number, char *result)
fract = (10 * fract + 512) / 1024;
/* if the result would be >= 10, round main number */
- if (fract == 10) {
+ if (fract >= 10) {
if (number >= 0)
number++;
else
number--;
fract = 0;
+ } else if (fract < 0) {
+ /* shouldn't happen */
+ fract = 0;
}
if (number == 0)