uutils / uutils/coreutils

parse_percent_values always setting percentage to 0 doing double multiplication to 1024

Open
#10,803 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

U - sort
Dominant language
Rust
Stars
24.1k
Forks
2k
Avg merge
1d 5h
Merged PRs (30d)
365

Description

I was investigating what procfs was used for and I was looking into the implementation of reading the total amount of memory and saw that we multiply the output by 1024 even though the output is already returned in bytes by procfs.

The second bug I saw in the implementation is that this was implemented as an int:

Ok(total) => Ok((number / 100) * total),

Which always equals 0 and it needs to be changed to this:

Ok(total) => Ok(total * number / 100),

Taking a look at the implementation of how procfs reads these values its very simple and the dependency chain for procfs is massive and brings in other large dependencies such as chrono that we do not use anymore.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the parse_percent_values implementation and trace how procfs supplies total memory and percentage values. Verify the units and integer arithmetic, then inspect the procfs dependency chain; done means percentage calculations are nonzero and memory is not multiplied by 1024 twice, with the unnecessary dependency concerns addressed.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
cli, operating-systems
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.