bin/171487: humanize_number(3) fails to show HN_IEC_PREFIXES correctly

Matthew Seaman matthew at FreeBSD.org
Sun Sep 9 06:40:06 UTC 2012


>Number:         171487
>Category:       bin
>Synopsis:       humanize_number(3) fails to show HN_IEC_PREFIXES correctly
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun Sep 09 06:40:05 UTC 2012
>Closed-Date:
>Last-Modified:
>Originator:     Matthew Seaman
>Release:        FreeBSD 9.0-STABLE amd64
>Organization:
Infracaninophile
>Environment:
System: FreeBSD lucid-nonsense.infracaninophile.co.uk 9.0-STABLE FreeBSD 9.0-STABLE #18 r237463: Sat Jun 23 07:14:31 BST 2012 root at lucid-nonsense.infracaninophile.co.uk:/usr/obj/usr/src/sys/LUCID-NONSENSE amd64


	
>Description:

An off-by-one error means that humanize_number(3) can't produce the
IEC / SI binary prefixes (Ki,  Mi, Gi, etc) correctly.

>How-To-Repeat:

worm:/tmp:% cat foo.c
#include <libutil.h>
#include <stdio.h>

int
main (__unused int argc, __unused const char *argv[])
{
	char	buf[12];

	humanize_number(buf, sizeof(buf), 1048576, "", 1, HN_IEC_PREFIXES);
	printf("%s\n", buf);
}
worm:/tmp:% clang -lutil -o foo foo.c
worm:/tmp:% ./foo
1024 i

After applying the patch:

worm:/tmp:% ./foo
1024 Ki

>Fix:

	

--- HN.diff begins here ---
Index: humanize_number.c
===================================================================
--- humanize_number.c	(revision 238771)
+++ humanize_number.c	(working copy)
@@ -76,7 +76,7 @@
 		if (flags & HN_B)
 			prefixes = "B\0\0Ki\0Mi\0Gi\0Ti\0Pi\0Ei";
 		else
-			prefixes = "\0\0Ki\0Mi\0Gi\0Ti\0Pi\0Ei";
+			prefixes = "\0\0\0Ki\0Mi\0Gi\0Ti\0Pi\0Ei";
 	} else {
 		baselen = 1;
 		if (flags & HN_DIVISOR_1000)
--- HN.diff ends here ---


>Release-Note:
>Audit-Trail:
>Unformatted:


More information about the freebsd-bugs mailing list