]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/commit
MFC r327317:
authorrobak <robak@ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f>
Tue, 3 Jul 2018 14:57:11 +0000 (14:57 +0000)
committerrobak <robak@ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f>
Tue, 3 Jul 2018 14:57:11 +0000 (14:57 +0000)
commitacfd000f19711fb8133d88c2c4f820e8d1c41c2a
tree4edf94ba38aa83e0da322fc781bc627f9acd45b5
parentecbfaf82780cc3102b3c7801bde84721c3980899
MFC r327317:

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

git-svn-id: svn://svn.freebsd.org/base/stable/10@335891 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
lib/libutil/humanize_number.3
lib/libutil/humanize_number.c
lib/libutil/tests/humanize_number_test.c