aboutsummaryrefslogtreecommitdiff
path: root/lib/libutil/humanize_number.3
diff options
context:
space:
mode:
authorBartek Rutkowski <robak@FreeBSD.org>2017-12-28 22:57:34 +0000
committerBartek Rutkowski <robak@FreeBSD.org>2017-12-28 22:57:34 +0000
commite285e32e5615d20b4899c4f82d5c88a81ec49395 (patch)
treebf614065f9505a3ad46a171966b713ef72135836 /lib/libutil/humanize_number.3
parent0080a8fa9501604a7324872534728b7b72481e37 (diff)
downloadsrc-e285e32e5615d20b4899c4f82d5c88a81ec49395.tar.gz
src-e285e32e5615d20b4899c4f82d5c88a81ec49395.zip
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
Notes
Notes: svn path=/head/; revision=327317
Diffstat (limited to 'lib/libutil/humanize_number.3')
-rw-r--r--lib/libutil/humanize_number.36
1 files changed, 6 insertions, 0 deletions
diff --git a/lib/libutil/humanize_number.3 b/lib/libutil/humanize_number.3
index 3a883caf2e94..9259f377abf2 100644
--- a/lib/libutil/humanize_number.3
+++ b/lib/libutil/humanize_number.3
@@ -200,3 +200,9 @@ The
.Dv HN_IEC_PREFIXES
flag was introduced in
.Fx 9.0 .
+.Sh CAVEATS
+For numbers greater than 999 using buffer length of 4 and less can cause
+rounding errors.
+When using
+.Dv HN_IEC_PREFIXES
+the same error occurs for buffer length of 5 or less.