Skip to content

Commit

Permalink
gettime: silence sanitizer overflow warning
Browse files Browse the repository at this point in the history
A warning is triggered in clang's unsigned integer sanitizer while two
seq values are subtracted from each other during the clock_cmp qsort
comparator:

gettime.c:657:17: runtime error: unsigned integer overflow: 2 - 3 cannot be represented in type 'unsigned int'

While pedantically correct, the issue is harmless since the result is
ultimately cast into a (signed) int on the function's return thus it
will be interpreted correctly within qsort. However it's easy to silence
the warning by changing clock_entry.seq from a uint32_t to a int32_t so
even though we've reduced the range we hopefully make it easier to see
and diagnose real overflow issues sooner in the future.

Signed-off-by: Sitsofe Wheeler <sitsofe@yahoo.com>
  • Loading branch information
sitsofe committed Oct 15, 2017
1 parent c13a60c commit 3082c4e
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion gettime.c
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ uint64_t time_since_now(const struct timespec *s)
#define CLOCK_ENTRIES_TEST 1000

struct clock_entry {
uint32_t seq;
int32_t seq;
uint32_t cpu;
uint64_t tsc;
};
Expand Down

0 comments on commit 3082c4e

Please sign in to comment.