Open
Description
- Version of collectd: v6 HEAD, v5 HEAD
Steps to reproduce
grep UINT_MAX src/disk.c
Expected output
Correct max value used in wrap up calculations.
Actual output
Both v5 (main
) and v6 (collectd-6.0
) HEAD give:
src/disk.c: diff_read_sectors = 1 + read_sectors + (UINT_MAX - ds->read_sectors);
src/disk.c: diff_write_sectors = 1 + write_sectors + (UINT_MAX - ds->write_sectors);
src/disk.c: diff_read_ops = 1 + read_ops + (UINT_MAX - ds->read_ops);
src/disk.c: diff_write_ops = 1 + write_ops + (UINT_MAX - ds->write_ops);
src/disk.c: diff_read_time = 1 + read_time + (UINT_MAX - ds->read_time);
src/disk.c: diff_write_time = 1 + write_time + (UINT_MAX - ds->write_time);
src/disk.c: diff_io_time = 1 + io_time + (UINT_MAX - ds->io_time);
Bug description
Above variables and struct members are 64-bit (signed) derive_t
values, whereas UINT_MAX
is 32-bit (unsigned) value.
According to kernel documentation, values read from /proc/diskstats
are unsigned long (native word size) numbers, i.e. UINT_MAX
is correct only for 32-bit platforms: https://www.kernel.org/doc/Documentation/iostats.txt
(Whereas most machines today are running 64-bit Linux.)
Noticed while reviewing #4217.