Building with clang results in the following warning: posix_timers.c:69:6: warning: absolute value function 'abs' given an argument of type 'long long' but has parameter of type 'int' which may cause truncation of value [-Wabsolute-value] if (abs(diff - DELAY * USECS_PER_SEC) > USECS_PER_SEC / 2) { ^ So switch to using llabs() instead.
Unified · Split
| @@ -66,7 +66,7 @@ static int check_diff(struct timeval start, struct timeval end) · 65 unmodified lines | |||
| 66 | diff = end.tv_usec - start.tv_usec; | 66 | diff = end.tv_usec - start.tv_usec; |
| 67 | diff += (end.tv_sec - start.tv_sec) * USECS_PER_SEC; | 67 | diff += (end.tv_sec - start.tv_sec) * USECS_PER_SEC; |
| 68 | 68 | ||
| 69 | if (abs(diff - DELAY * USECS_PER_SEC) > USECS_PER_SEC / 2) { | 69 | if (llabs(diff - DELAY * USECS_PER_SEC) > USECS_PER_SEC / 2) { |
| 70 | printf("Diff too high: %lld..", diff); | 70 | printf("Diff too high: %lld..", diff); |
| 71 | return -1; | 71 | return -1; |
| 72 | } | 72 | } |