[BusyBox] bug#1189: make_human_readable_str chokes with big numbers (GB/TB values)

Adam Slattery aslattery at sunriselinux.com
Fri Jun 29 15:00:03 UTC 2001


package: busybox
version: 0.51
(latest cvs Jun 29 06:00)


busybox df -h (with the patch I just submitted for the blocksize bug):
 /dev/ide/host0/bus0/target0/lun0/part2   inf   883M    983M  47%  /usr

fileutils df -h:
 /dev/ide/host0/bus0/target0/lun0/part2   1.9G  883M    983M  47% /usr

This isn't good :).

The problem is that in human_readable.c, a 32 bit variable ends up getting
shifted left 40 bits when you have a GB size.  The fix is to use a
variable as big as the result size (long double). A small problem arrises:
you can't bitshift long double on 32 bit archetectures. So instead we can
just multiply and divide by 1024 (*1024 is the same as <<10).


Adam Slattery
Sunrise Linux Development Team


--- human_readable.c.oldff -u huFri Jun 29 15:20:01 2001
+++ human_readable.c    Fri Jun 29 15:38:25 2001
@@ -38,16 +38,16 @@
        } else {
                /* Ok, looks like they want us to autoscale */
                int i=0;
-               unsigned long divisor = 1;
+               long double divisor = 1;
                long double result = size*block_size;
                for(i=0; i <= 4; i++) {
-                       divisor<<=10;
+                       divisor *= 1024;
                        if (result <= divisor) {
-                               divisor>>=10;
+                               divisor /= 1024;
                                break;
                        }
                }








More information about the busybox mailing list