comedi_test: deal with INSN_GTOD values more carefully
Try and avoid arithmetic overflow when converting the difference between two INSN_GTOD timestamps to a signed number of microseconds.
This commit is contained in:
parent
a4dd004076
commit
c45f319171
1 changed files with 13 additions and 2 deletions
|
@ -19,6 +19,7 @@ int test_insn_read_time(void)
|
|||
comedi_insnlist il;
|
||||
lsampl_t t1[2],t2[2];
|
||||
lsampl_t data;
|
||||
long diffus;
|
||||
int save_errno;
|
||||
int ret;
|
||||
|
||||
|
@ -60,8 +61,18 @@ int test_insn_read_time(void)
|
|||
printf("W: comedi_do_insn: returned %d (expected 3)\n",ret);
|
||||
}
|
||||
|
||||
printf("read time: %ld us\n",
|
||||
(long)(t2[0]-t1[0])*1000000+(t2[1]-t1[1]));
|
||||
if (t2[0] >= t1[0]) {
|
||||
diffus = (long)(t2[0] - t1[0]);
|
||||
} else {
|
||||
diffus = -(long)(t1[0] - t2[0]);
|
||||
}
|
||||
diffus *= 1000000;
|
||||
if (t2[1] >= t1[1]) {
|
||||
diffus += (long)(t2[1] - t1[1]);
|
||||
} else {
|
||||
diffus -= (long)(t1[1] - t2[1]);
|
||||
}
|
||||
printf("read time: %ld us\n", diffus);
|
||||
|
||||
|
||||
return 0;
|
||||
|
|
Loading…
Add table
Reference in a new issue