diff options
author | Rolf Eike Beer <eike@sf-mail.de> | 2018-06-26 09:39:19 +0200 |
---|---|---|
committer | Nikos Mavrogiannopoulos <nmav@redhat.com> | 2018-06-26 12:37:28 +0200 |
commit | e79361f9040a0a59e30aa672240ce2cf42c5ccf5 (patch) | |
tree | 7c6eb275dab54c306f162e4a25fa4e7bb62c0ad7 | |
parent | 69225bade584a91d429fbce0db136dc004631f20 (diff) | |
download | gnutls-e79361f9040a0a59e30aa672240ce2cf42c5ccf5.tar.gz |
avoid rounding errors and overflows when substracting timespecs
The current Unix time will cause overflows if multiplied with 1000, which could
lead to rounding errors afterwards. Do the substractions first so all numbers
stay small enough to fit into unsigned ints.
Signed-off-by: Rolf Eike Beer <eike@sf-mail.de>
-rw-r--r-- | src/benchmark.h | 3 |
1 files changed, 1 insertions, 2 deletions
diff --git a/src/benchmark.h b/src/benchmark.h index e13d9a3850..a59e088e29 100644 --- a/src/benchmark.h +++ b/src/benchmark.h @@ -62,6 +62,5 @@ double stop_benchmark(struct benchmark_st *st, const char *metric, inline static unsigned int timespec_sub_ms(struct timespec *a, struct timespec *b) { - return (a->tv_sec * 1000 + a->tv_nsec / (1000 * 1000) - - (b->tv_sec * 1000 + b->tv_nsec / (1000 * 1000))); + return (a->tv_sec - b->tv_sec) * 1000 + (a->tv_nsec - b->tv_nsec) / (1000 * 1000); } |