From 1304a8ea0d5c252bcca42ad0d5da04ac2a339769 Mon Sep 17 00:00:00 2001 From: ThePeGaSuS <25697531+TehPeGaSuS@users.noreply.github.com> Date: Sat, 5 Sep 2026 21:00:36 +0200 Subject: [PATCH] sysinfo.pl 1.2.3: fix memory used/free swapped in display and percent memoryusage() computed $vard as actual used memory (Total - Free - Buffers - Cached), but the final return statement treated it as if it were free memory: it displayed human_size($vara-$vard) as "used" and computed the percentage as 100-($vard/($vara-$vard)*100). This mislabeled free memory as used in the output, and produced a negative percentage whenever used memory exceeded free memory (e.g. '2.83GB/7.57GB (-67.52%)' on a host where 4.74GB was actually in use). Fix by using $vard directly as used memory in both the display and the percentage calculation. --- perl/sysinfo.pl | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/perl/sysinfo.pl b/perl/sysinfo.pl index 5c87a9da..0b8fa88f 100644 --- a/perl/sysinfo.pl +++ b/perl/sysinfo.pl @@ -39,6 +39,10 @@ # # ported to WeeChat (http://www.weechat.org/) by Nils Görs. # +# 2026-09-05: 1.2.3 TehPeGaSuS +# : fix: memoryusage() showed free memory mislabeled as used, and +# the percentage could go negative, because the used/free values +# were swapped in the final display/percent calculation # 2026-09-05: 1.2.2 TehPeGaSuS # : fix: memory usage broken (uninitialized values / division by 0, # closes #581) on kernel >= 6.x due to kernel version regex only @@ -83,7 +87,7 @@ use strict; my $SCRIPT_NAME = "sysinfo"; -my $SCRIPT_VERSION = "1.2.2"; +my $SCRIPT_VERSION = "1.2.3"; my $SCRIPT_DESCR = "provides a system info command"; my $SCRIPT_LICENSE = "BSD-2-Clause"; my $SCRIPT_AUTHOR = "Nils Görs "; @@ -884,8 +888,8 @@ sub memoryusage { $vard = `vmstat -s | grep 'pages active' | awk '{print \$1}'` * `vmstat -s | grep 'per page' | awk '{print \$1}'`; $vara = `$sysctl -n hw.physmem`; } - $varp = sprintf("%.2f", 100-($vard / ($vara-$vard) * 100)); - return human_size($vara-$vard)."/".human_size($vara)." ($varp%)"; + $varp = sprintf("%.2f", ($vard / $vara) * 100); + return human_size($vard)."/".human_size($vara)." ($varp%)"; } sub networkinfobsd {