mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 06:05:27 +00:00
virhostuptime: Fix rounding in uptime calculation
"f + 0.5" does not round correctly for values very close to ".5" for every integer multiple, e.g. "0.499999975". Found by clang-tidy's "bugprone-incorrect-roundings" check. Signed-off-by: Tim Wiederhake <twiederh@redhat.com> Reviewed-by: Peter Krempa <pkrempa@redhat.com>
This commit is contained in:
parent
795187fe0c
commit
2cdbfbe7ac
@ -32,6 +32,8 @@
|
||||
#include "virtime.h"
|
||||
#include "virthread.h"
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#define VIR_FROM_THIS VIR_FROM_NONE
|
||||
|
||||
VIR_LOG_INIT("util.virhostuptime");
|
||||
@ -76,7 +78,7 @@ virHostGetBootTimeProcfs(unsigned long long *btime)
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
*btime = now / 1000 - up + 0.5;
|
||||
*btime = llround(now / 1000 - up);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user