Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. =================================================================== RCS file: /ftp/cvs/cvsroot/src/lib/libc/gen/humanize_number.c,v rcsdiff: /ftp/cvs/cvsroot/src/lib/libc/gen/humanize_number.c,v: warning: Unknown phrases like `commitid ...;' are present. retrieving revision 1.11 retrieving revision 1.12 diff -u -p -r1.11 -r1.12 --- src/lib/libc/gen/humanize_number.c 2006/06/08 21:08:56 1.11 +++ src/lib/libc/gen/humanize_number.c 2007/03/13 02:52:10 1.12 @@ -1,4 +1,4 @@ -/* $NetBSD: humanize_number.c,v 1.11 2006/06/08 21:08:56 simonb Exp $ */ +/* $NetBSD: humanize_number.c,v 1.12 2007/03/13 02:52:10 enami Exp $ */ /* * Copyright (c) 1997, 1998, 1999, 2002 The NetBSD Foundation, Inc. @@ -39,7 +39,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: humanize_number.c,v 1.11 2006/06/08 21:08:56 simonb Exp $"); +__RCSID("$NetBSD: humanize_number.c,v 1.12 2007/03/13 02:52:10 enami Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" @@ -121,7 +121,12 @@ humanize_number(char *buf, size_t len, i for (max = 100, i = len - baselen; i-- > 0;) max *= 10; - for (i = 0; bytes >= max && i < maxscale; i++) + /* + * Divide the number until it fits the given column. + * If there will be an overflow by the rounding below, + * divide once more. + */ + for (i = 0; bytes >= max - 50 && i < maxscale; i++) bytes /= divisor; if (scale & HN_GETSCALE)