From owner-freebsd-bugs@FreeBSD.ORG Sat Oct 7 02:40:28 2006 Return-Path: X-Original-To: freebsd-bugs@hub.freebsd.org Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 6A88A16A407 for ; Sat, 7 Oct 2006 02:40:28 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 3460C43D46 for ; Sat, 7 Oct 2006 02:40:28 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.4/8.13.4) with ESMTP id k972eSGM088968 for ; Sat, 7 Oct 2006 02:40:28 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.13.4/8.13.4/Submit) id k972eSmT088967; Sat, 7 Oct 2006 02:40:28 GMT (envelope-from gnats) Date: Sat, 7 Oct 2006 02:40:28 GMT Message-Id: <200610070240.k972eSmT088967@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org From: Ricardo Nabinger Sanchez Cc: Subject: Re: bin/102694: df(1) can forget to print the unit with -h X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Ricardo Nabinger Sanchez List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 07 Oct 2006 02:40:28 -0000 The following reply was made to PR bin/102694; it has been noted by GNATS. From: Ricardo Nabinger Sanchez To: bug-followup@FreeBSD.org Cc: ceri@FreeBSD.org Subject: Re: bin/102694: df(1) can forget to print the unit with -h Date: Fri, 6 Oct 2006 23:36:34 -0300 > Not sure if this is df(1) or libutil's humanize_number(3) > to be honest. I was looking at it and was able to reproduce it and found what's going on. What happens is that, for numbers close to the next scale (1000<= x <1024), the scaled number is big for the 6-char buffer, which in fact is told be be 6-1 bytes. From the source: humanize_number(buf, sizeof(buf) - (bytes < 0 ? 0 : 1), bytes, "", HN_AUTOSCALE, flags); That "sizeof(buf) - (bytes < 0 ? 0 : 1)" causes humanize_number to think that the buffer has only 5 chars, thus producing: [ ][1][0][0][0][\0] If one remove that restriction, the unit comes back: [1][0][0][0][M][\0] The drawback is that it no longer scales "humanly" for numbers >= 1024, going up to 9999 (ugly). I spent a good time trying to figure out a clean and effective solution, but the best I got was to not use humanize_number, and scale the number locally. If that is good enough, I can clean up my code and send a patch. Regards. -- Ricardo Nabinger Sanchez Powered by FreeBSD "Left to themselves, things tend to go from bad to worse."