History

selftests: timers: Fix abs() warning in posix_timers test

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.

John Stultz committed 2 years ago

Commit ed366de1 parent f7d5bcd1 file · +1 −1Browse files

Unified · Split

tools/testing/selftests/timers/posix_timers.c+1−1
@@ -66,7 +66,7 @@ static int check_diff(struct timeval start, struct timeval end) · 65 unmodified lines
6666 diff = end.tv_usec - start.tv_usec;
6767 diff += (end.tv_sec - start.tv_sec) * USECS_PER_SEC;
6868
69− if (abs(diff - DELAY * USECS_PER_SEC) > USECS_PER_SEC / 2) {
69+ if (llabs(diff - DELAY * USECS_PER_SEC) > USECS_PER_SEC / 2) {
7070 printf("Diff too high: %lld..", diff);
7171 return -1;
7272 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t