freebsd-nq/lib/libutil
Bartek Rutkowski e285e32e56 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
..
tests
_secure_path.3
_secure_path.c
auth.c
expand_number.3
expand_number.c
flopen.3
flopen.c
fparseln.3
fparseln.c
gr_util.c
hexdump.3
hexdump.c
humanize_number.3
humanize_number.c
kinfo_getallproc.3
kinfo_getallproc.c
kinfo_getfile.3
kinfo_getfile.c
kinfo_getproc.3
kinfo_getproc.c
kinfo_getvmmap.3
kinfo_getvmmap.c
kinfo_getvmobject.3
kinfo_getvmobject.c
kld.3
kld.c
libutil.h
login_auth.3
login_auth.c
login_cap.3
login_cap.c
login_cap.h
login_class.3
login_class.c
login_crypt.c
login_ok.3
login_ok.c
login_times.3
login_times.c
login_tty.3
login_tty.c
login.conf.5
Makefile
Makefile.depend
pidfile.3
pidfile.c
property.3
property.c
pty.3
pty.c
pw_util.3
pw_util.c
quotafile.3
quotafile.c
realhostname_sa.3
realhostname.3
realhostname.c
stub.c
trimdomain.3
trimdomain.c
uucplock.3
uucplock.c