vmstat: Errors in calculations
In src/vmstat.c
:
- It seems that
cpu_gue
may be calculated incorrectly in the second and subsequent lines of wide VM-mode output:stat_GST
andstat_GNI
are interpreted asllu
instead ofld
. Also, looks like a possible UB. - There's a type mismatch in the global and local output repetition counters.
- I cannot reproduce #252, but the constraining of
cpu_*
into anunsigned
in VM-mode printf seems unnecessary, at least. Outputting them aslld
may shed some more light on the issue. There's unchecked arithmetic all over the place on signed types. According tolinux/Documentation/filesystems/proc.rst
, iowait, for instance, is unreliable in/proc/stat
and may decrease over time. That may produce a negativeDiv
as well.
In library/stat.c
:
- In the macro
TICsetH
for calculating value deltas a huge ULL can be assigned to a smaller int (signed or unsigned) when new_value < previous_value. May affect #252, because iowait can decrease.
Edited by Roman Žilka