Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 22 Aug 2010 23:21:42 +0200
From:      Dimitry Andric <dimitry@andric.com>
To:        =?UTF-8?B?RGFnLUVybGluZyBTbcO4cmdyYXY=?= <des@des.no>
Cc:        Bruce Cran <bruce@cran.org.uk>, svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org
Subject:   Re: svn commit: r211304 - head/lib/libutil
Message-ID:  <4C7194E6.6080708@andric.com>
In-Reply-To: <86wrrraqk8.fsf@ds4.des.no>
References:  <201008141434.o7EEYaSA030301@svn.freebsd.org>	<20100815205724.00007e0f@unknown> <86wrrraqk8.fsf@ds4.des.no>

next in thread | previous in thread | raw e-mail | index | archive | help
This is a multi-part message in MIME format.
--------------040200060404010907090506
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

On 2010-08-16 10:51, Dag-Erling Sm=C3=B8rgrav wrote:
> Bruce Cran <bruce@cran.org.uk> writes:
>> Somewhat related, there are overflow bugs in humanize_number - for
>> example df(1) fails to display space from a 100PB filesystem
>> correctly.
>=20
> Patch?  :)

Attached.  This makes humanize_number() work properly for all possible
int64_t values.

It has one significant behaviour change, though: with the original
version of humanize_number(), if you used a fixed scale parameter, and
the number was larger than the buffer could contain, it would simply
stomp over the end of the buffer.  With this fix, it will return -1
instead.  I hope you agree that is better. :)

--------------040200060404010907090506
Content-Type: text/plain;
 name="humanize-overflow-fix.diff"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
 filename="humanize-overflow-fix.diff"

ZGlmZiAtLWdpdCBhL2xpYi9saWJ1dGlsL2h1bWFuaXplX251bWJlci5jIGIvbGliL2xpYnV0
aWwvaHVtYW5pemVfbnVtYmVyLmMKaW5kZXggZGU5ODU4Ny4uYTMwNDEzNyAxMDA2NDQKLS0t
IGEvbGliL2xpYnV0aWwvaHVtYW5pemVfbnVtYmVyLmMKKysrIGIvbGliL2xpYnV0aWwvaHVt
YW5pemVfbnVtYmVyLmMKQEAgLTQyLD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QgPj0gbWF4
KQorCQkJcmV0dXJuICgtMSk7CisJfQogCi0JLyogSWYgYSB2YWx1ZSA8PSA5LjkgYWZ0ZXIg
cm91bmRpbmcgYW5kIC4uLiAqLwotCWlmIChieXRlcyA8IDk5NSAmJiBpID4gMCAmJiBmbGFn
cyAmIEhOX0RFQ0lNQUwpIHsKKwkvKiBJZiBxdW90aWVudCA8IDEwIGFmdGVyIHJvdW5kaW5n
IGFuZCAuLi4gKi8KKwlpZiAocXVvdHIgPCAxMCAmJiBpID4gMCAmJiBmbGFncyAmIEhOX0RF
Q0lNQUwpIHsKIAkJLyogYmFzZWxlbiArIFwwICsgLk4gKi8KIAkJaWYgKGxlbiA8IGJhc2Vs
ZW4gKyAxICsgMikKIAkJCXJldHVybiAoLTEpOwotCQliID0gKChpbnQpYnl0ZXMgKyA1KSAv
IDEwOwotCQlzMSA9IGIgLyAxMDsKLQkJczIgPSBiICUgMTA7CiAJCXIgPSBzbnByaW50Zihi
dWYsIGxlbiwgIiVkJXMlZCVzJXMlcyIsCi0JCSAgICBzaWduICogczEsIGxvY2FsZWNvbnYo
KS0+ZGVjaW1hbF9wb2ludCwgczIsCisJCSAgICBzaWduICogKGludCkgcXVvdHIsIGxvY2Fs
ZWNvbnYoKS0+ZGVjaW1hbF9wb2ludCwgZnJhY3IsCiAJCSAgICBzZXAsIFNDQUxFMlBSRUZJ
WChpKSwgc3VmZml4KTsKIAl9IGVsc2UKIAkJciA9IHNucHJpbnRmKGJ1ZiwgbGVuLCAiJSIg
UFJJZDY0ICIlcyVzJXMiLAotCQkgICAgc2lnbiAqICgoYnl0ZXMgKyA1MCkgLyAxMDApLAor
CQkgICAgc2lnbiAqIHF1b3QsCiAJCSAgICBzZXAsIFNDQUxFMlBSRUZJWChpKSwgc3VmZml4
KTsKIAogCXJldHVybiAocik7Cg==
--------------040200060404010907090506--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4C7194E6.6080708>