Skip to content

sysinfo.pl 1.2.3: fix memory used/free swapped in display and percent - #611

Merged
flashcode merged 1 commit into
weechat:mainfrom
TehPeGaSuS:fix-sysinfo-memory-percent
Sep 5, 2026
Merged

sysinfo.pl 1.2.3: fix memory used/free swapped in display and percent#611
flashcode merged 1 commit into
weechat:mainfrom
TehPeGaSuS:fix-sysinfo-memory-percent

Conversation

@TehPeGaSuS

Copy link
Copy Markdown
Contributor

memoryusage() computes $vard as the actual used memory (Total - Free - Buffers - Cached), but the final return statement treats it as if it were free memory instead:

$varp = sprintf("%.2f", 100-($vard / ($vara-$vard) * 100));
return human_size($vara-$vard)."/".human_size($vara)." ($varp%)";

This mislabels free memory as used in the displayed output, and can produce a negative percentage whenever used memory exceeds free memory, e.g.:

Memory Usage: 2.83GB/7.57GB (-67.52%)

(on a host where 4.74GB was actually in use, i.e. ~62.6%).

Fix by using $vard directly for both the display and the percentage:

$varp = sprintf("%.2f", ($vard / $vara) * 100);
return human_size($vard)."/".human_size($vara)." ($varp%)";

This follows up #610 (merged as 1.2.2), which fixed the kernel-version detection but left this separate used/free swap in place.

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.
@flashcode flashcode self-assigned this Sep 5, 2026
@flashcode flashcode added the bug Unexpected problem or unintended behavior label Sep 5, 2026
@flashcode
flashcode merged commit ebe9bb4 into weechat:main Sep 5, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Unexpected problem or unintended behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants