Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-6]: src/lib/libc/gen Pull up following revision(s) (requested by ...



details:   https://anonhg.NetBSD.org/src/rev/449a361c7161
branches:  netbsd-6
changeset: 773943:449a361c7161
user:      riz <riz%NetBSD.org@localhost>
date:      Mon Mar 19 23:24:58 2012 +0000

description:
Pull up following revision(s) (requested by dholland in ticket #129):
        lib/libc/gen/humanize_number.c: revision 1.16
PR/44097: Yamamoto Takashi: Prevent overflow.

diffstat:

 lib/libc/gen/humanize_number.c |  22 +++++++++++++++++-----
 1 files changed, 17 insertions(+), 5 deletions(-)

diffs (61 lines):

diff -r b1b2f51a8f06 -r 449a361c7161 lib/libc/gen/humanize_number.c
--- a/lib/libc/gen/humanize_number.c    Mon Mar 19 23:23:10 2012 +0000
+++ b/lib/libc/gen/humanize_number.c    Mon Mar 19 23:24:58 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: humanize_number.c,v 1.14 2008/04/28 20:22:59 martin Exp $      */
+/*     $NetBSD: humanize_number.c,v 1.14.24.1 2012/03/19 23:24:58 riz Exp $    */
 
 /*
  * Copyright (c) 1997, 1998, 1999, 2002 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 
 #include <sys/cdefs.h>
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: humanize_number.c,v 1.14 2008/04/28 20:22:59 martin Exp $");
+__RCSID("$NetBSD: humanize_number.c,v 1.14.24.1 2012/03/19 23:24:58 riz Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #include "namespace.h"
@@ -49,7 +49,7 @@
 {
        const char *prefixes, *sep;
        int     b, i, r, maxscale, s1, s2, sign;
-       int64_t divisor, max;
+       int64_t divisor, max, post = 1;
        size_t  baselen;
 
        _DIAGASSERT(buf != NULL);
@@ -89,12 +89,23 @@
                buf[0] = '\0';
        if (bytes < 0) {
                sign = -1;
-               bytes *= -100;
                baselen = 3;            /* sign, digit, prefix */
+               if (-bytes < INT64_MAX / 100)
+                       bytes *= -100;
+               else {
+                       bytes = -bytes;
+                       post = 100;
+                       baselen += 2;
+               }
        } else {
                sign = 1;
-               bytes *= 100;
                baselen = 2;            /* digit, prefix */
+               if (bytes < INT64_MAX / 100)
+                       bytes *= 100;
+               else {
+                       post = 100;
+                       baselen += 2;
+               }
        }
        if (flags & HN_NOSPACE)
                sep = "";
@@ -126,6 +137,7 @@
        } else
                for (i = 0; i < scale && i < maxscale; i++)
                        bytes /= divisor;
+       bytes *= post;
 
        /* If a value <= 9.9 after rounding and ... */
        if (bytes < 995 && i > 0 && flags & HN_DECIMAL) {



Home | Main Index | Thread Index | Old Index