]> git.ipfire.org Git - thirdparty/openssh-portable.git/commitdiff
sync fmt_scaled.c
authorDamien Miller <djm@mindrot.org>
Mon, 14 May 2018 04:40:08 +0000 (14:40 +1000)
committerDamien Miller <djm@mindrot.org>
Mon, 14 May 2018 04:40:08 +0000 (14:40 +1000)
revision 1.17
date: 2018/05/14 04:39:04;  author: djm;  state: Exp;  lines: +5 -2;
commitid: 53zY8GjViUBnWo8Z;
constrain fractional part to [0-9] (less confusing to static analysis); ok ian@

openbsd-compat/fmt_scaled.c

index f68f2412300ab5a20d478c01fe45da1242b87625..2f76ef931bb1c4fdbc202778fc3f3b4f19760d2f 100644 (file)
@@ -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.
@@ -246,12 +246,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)