Commit Graph

17 Commits

Author SHA1 Message Date
robak
a9b02c6e96 humanize_number(3): fix math edge case in rounding large numbers
Fix for remainder overflow, when in rare cases adding remainder to divider
exceeded 1 and turned the total to 1000 in final formatting, taking up
the space for the unit character.

The fix continues the division of the original number if the above case
happens -- added the appropriate check to the for loop performing
the division. This lowers the value shown, to make it fit into the buffer
space provided (1.0M for 4+1 character buffer, as used by ls).

Add test case for the reported bug and extend test program to support
providing buffer length (ls -lh uses 5, tests hard-coded 4).

PR:		224498
Submitted by:	Pawel Biernacki <pawel.biernacki@gmail.com>
Reported by:	Masachika Ishizuka <ish@amail.plala.or.jp>
Reviewed by:	cem, kib
Approved by:	cem, kib
MFC after:	1 week
Sponsored by:	Mysterious Code Ltd.
Differential Revision:	D13578
2017-12-28 22:57:34 +00:00
jmg
ec9fa283ad don't assert on bad args, instead return an error..
Since so many programs don't check return value, always NUL terminate
the buf...

fix rounding when using base 1024 (the bug that started it all)...

add a set of test cases so we can make sure that things don't break
in the future...

Thanks to Clifton Royston for testing and the test program...

Approved by:	re (hrs, glebius)
MFC after:	1 week
2013-10-07 22:22:57 +00:00
delphij
c14cd58282 Add support for IEE/IEC (and now also SI) power of two notions of
prefixes (Ki, Mi, Gi...) for humanize_number(3).

Note that applications has to pass HN_IEC_PREFIXES to use this
feature for backward compatibility reasons.

Reviewed by:	arundel
MFC after:	2 weeks
2011-04-12 22:48:03 +00:00
gjb
0d69b2025b s/buffer/buf as is used in the code.
Submitted by:	arundel (via doc@)
MFC after:	3 days
2011-03-21 23:59:20 +00:00
joel
8bf8866210 The NetBSD Foundation has granted permission to remove clause 3 and 4 from
their software.

Obtained from:	NetBSD
2010-03-02 17:06:40 +00:00
obrien
4657f1f225 Adjust history.
Approved by:	re(ken)
2007-09-28 15:31:44 +00:00
pjd
7002fe2c1f Point expand_number(3) at humanize_number(3) and nive versa.
Suggested by:	trhodes
Approved by:	re (kensmith)
2007-09-05 14:25:16 +00:00
ru
f4eec08060 Markup fixes. 2006-09-17 21:27:35 +00:00
imp
5d17f2bbe1 Note the convention that humanize_number follows.
Add 'engineering' numbers to table.
2006-07-15 20:53:36 +00:00
delphij
ecb578572b Remove duplicated "bytes".
Submitted by:	Wojciech A. Koszek [dunstan freebsd czest pl]
PR:		79747
2005-04-10 12:15:25 +00:00
pjd
b897378c21 Backout manual page updates.
Requested by:	ru
2004-09-26 12:08:31 +00:00
pjd
afbc779ed0 Take the lastest fixes from NetBSD.
Obtained from:	NetBSD
2004-09-25 14:11:34 +00:00
pjd
5b5cfb3bca There is no such manual page in FreeBSD. 2004-09-16 18:32:58 +00:00
ru
2b2d3c7563 Markup fixes. 2004-07-07 20:25:54 +00:00
pjd
4225bf90f0 Humanize_number(3) is a part of libutil. 2004-05-25 20:11:50 +00:00
trhodes
7fc50ba299 You want to include libutil.h, not util.h.
Some minor sentence tweaking.
2004-05-25 18:53:54 +00:00
pjd
d207894810 Add humanize_number(3) to libutil for formating numbers into a human
readable form.

Obtained from:	NetBSD
2004-05-24 22:19:27 +00:00