Skip to content

Commit

Permalink
phc2sys: Fix lower bound value of update_rate
Browse files Browse the repository at this point in the history
Following command produces unexpected update rate.
 # phc2sys -s eth0 -q -m -O0 -R1.0842021724855044e-19
This is caused by wrong validation of phc_interval related to
significant digits of double precision and phc_interval_tp.tv_sec
overflow.

To avoid these unwanted trouble, this patch limits lower bound of
phc_rate to 1e-9.
There is no profound meaning in the lower bound value. I just think
it's enough to actual use and it doesn't cause phc_interval_tp.tv_sec
overflow in not only 64bit environment but also 32bit environment.
Thereby, messy validation of phc_interval is no longer needed.

Signed-off-by: Ken ICHIKAWA <[email protected]>
  • Loading branch information
ichik1 authored and richardcochran committed Sep 4, 2013
1 parent 5bf265e commit b943ea2
Showing 1 changed file with 1 addition and 9 deletions.
10 changes: 1 addition & 9 deletions phc2sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -634,17 +634,9 @@ int main(int argc, char *argv[])
return -1;
break;
case 'R':
if (get_arg_val_d(c, optarg, &phc_rate, 0.0, DBL_MAX))
if (get_arg_val_d(c, optarg, &phc_rate, 1e-9, DBL_MAX))
return -1;
phc_interval = 1.0 / phc_rate;
/* phc_interval will be assigned to a time_t variable. */
/* check if that occurs overflow. */
if ((sizeof(time_t) == 8 && phc_interval > INT64_MAX) ||
(sizeof(time_t) == 4 && phc_interval > INT32_MAX)) {
fprintf(stderr,
"-R: %s is too small\n", optarg);
return -1;
}
break;
case 'N':
if (get_arg_val_i(c, optarg, &phc_readings, 1, INT_MAX))
Expand Down

0 comments on commit b943ea2

Please sign in to comment.