fastfetch-cli / fastfetch

An actively maintained, feature-rich and performance oriented, neofetch like system information tool.
MIT License
9.64k stars 388 forks source link

[BUG] loadvg_linux is wrong #1206

Closed Dariqq closed 3 weeks ago

Dariqq commented 3 weeks ago

Hi,

Looking through the loadavg code and in loadavg_linux.c fastfetch seems to read /proc/uptime instead of /proc/loadavg.

Also even if changing to /proc/loadavg (and removing the sysinfo code) the format string sscanf statement seems wrong:

cat /proc/loadavg
2.02 1.44 1.30 3/1633 102474

 ./fastfetch -s loadavg --format json
[
  {
    "type": "Loadavg",
    "result": [
      2.0,
      null,
      null
    ]
  }
]
Dariqq commented 3 weeks ago

Is the parsing of floats/doubles dependant on locales (whether , or . as seperator)?

Dariqq commented 3 weeks ago

It seems to be. If i run with LC_ALL=C the ourput of /proc/loadavg gets parsed correctly but with my default locale it is not

CarterLi commented 3 weeks ago

That was awful

Dariqq commented 3 weeks ago

this is after dropping the sysinfo call.

LC_ALL=C ./fastfetch -S loadavg --format json
[
  {
    "type": "Loadavg",
    "result": [
      0.41,
      0.48,
      0.54
    ]
  }
]

./fastfetch -S loadavg --format json
[
  {
    "type": "Loadavg",
    "result": [
      0.0,
      null,
      null
    ]
  }
]
CarterLi commented 3 weeks ago

This means that every scanf(%f) is buggy

Dariqq commented 3 weeks ago

Would it be safe to set LC_NUMERIC=C somewhere in the beginning?

Dariqq commented 3 weeks ago

mmh seems to parse string correctly when not using fastfetch

Dariqq commented 3 weeks ago

@CarterLi

Removing https://github.com/fastfetch-cli/fastfetch/blob/dev/src/common/init.c#L57 seems to work.