Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 9 Sep 2012 07:32:26 +0100 (BST)
From:      Matthew Seaman <matthew@FreeBSD.org>
To:        FreeBSD-gnats-submit@FreeBSD.org
Subject:   bin/171487: humanize_number(3) fails to show HN_IEC_PREFIXES correctly
Message-ID:  <201209090632.q896WQ9b011655@lucid-nonsense.infracaninophile.co.uk>
Resent-Message-ID: <201209090640.q896e5hs041399@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>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@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:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201209090632.q896WQ9b011655>