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:
Tim Wiederhake 2021-02-01 13:42:04 +01:00 committed by Peter Krempa
parent 795187fe0c
commit 2cdbfbe7ac

View File

@ -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;
}