diff --git a/NEWS b/NEWS index 89a52b10..b390b6af 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,7 @@ procps-ng-NEXT ---------------- * doc: Document I idle state in ps.1 and top.1 Debian #886967 + * free: fix some of the SI multiples issue #45 * kill: -l space between name parses correctly Debian #854407 * library: dont use vm_min_free on non Linux Debian #831396 * library: dont use SIGPWR on FreeBSD Debian #832148 diff --git a/free.c b/free.c index 6d81548e..08cb73bd 100644 --- a/free.c +++ b/free.c @@ -133,7 +133,7 @@ static const char *scale_size(unsigned long size, int flags, struct commandline_ if (args.exponent > 1) { /* In desired scale. */ snprintf(buf, sizeof(buf), "%ld", - (long int)((size / 1024) * base / power(base, args.exponent - 2)) + (long int)((size * 1024) / power(base, args.exponent-1)) ); return buf; } diff --git a/testsuite/free.test/free.exp b/testsuite/free.test/free.exp index 83e197e4..d019eb4c 100644 --- a/testsuite/free.test/free.exp +++ b/testsuite/free.test/free.exp @@ -19,12 +19,12 @@ set swaptotal [ expr { $swaptotal_kb * 1024 } ] spawn $free -b expect_pass "$test" "^${free_header}Mem:\\s+${memtotal}\\s+\\d+\\s+\\d+\\s+\\d+\\s+\\d+\\s+\\d+\\s*Swap:\\s+${swaptotal}\\s+\\d+\\s+\\d+\\s*" -foreach {arg divisor } {-k 1 -m 1024 -g 1048576 --mega 1000 --giga 1000000 } { +foreach {arg divisor } {-k 1024 -m 1048576 -g 1073741824 --kilo 1000 --mega 1000000 --giga 1000000000 } { set test "free with $arg argument" - set memtotal [ expr { $memtotal_kb / $divisor } ] - set swaptotal [ expr { $swaptotal_kb / $divisor } ] + set memtest [ expr { $memtotal / $divisor } ] + set swaptest [ expr { $swaptotal / $divisor } ] spawn $free $arg - expect_pass "$test" "^${free_header}Mem:\\s+$memtotal\\s+\\d+\\s+\\d+\\s+\\d+\\s+\\d+\\s+\\d+\\s*Swap:\\s+${swaptotal}\\s+\\d+\\s+\\d+\\s*" + expect_pass "$test" "^${free_header}Mem:\\s+$memtest\\s+\\d+\\s+\\d+\\s+\\d+\\s+\\d+\\s+\\d+\\s*Swap:\\s+${swaptest}\\s+\\d+\\s+\\d+\\s*" } #set test "free with human readable output"