From 468ab0172833be82f55c36ed99b5086961acb6d3 Mon Sep 17 00:00:00 2001 From: djm <> Date: Mon, 14 May 2018 04:39:04 +0000 Subject: [PATCH] constrain fractional part to [0-9] (less confusing to static analysis); ok ian@ --- src/lib/libutil/fmt_scaled.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/lib/libutil/fmt_scaled.c b/src/lib/libutil/fmt_scaled.c index 7a4dee2d..f9c8f65c 100644 --- a/src/lib/libutil/fmt_scaled.c +++ b/src/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)