From f6320e70507e02ce58e509431f7ed0a1a544a82e Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Mon, 7 Jun 2010 14:14:53 +0200 Subject: [PATCH] Don't hang in our_round The routine could loop infinitely when rounding a large value, replace it with our_lround. --- sys_linux.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/sys_linux.c b/sys_linux.c index c40e99c3..64174528 100644 --- a/sys_linux.c +++ b/sys_linux.c @@ -119,18 +119,9 @@ static void handle_end_of_slew(void *anything); /* ================================================== */ -inline static int -our_round(double x) { - int y; - y = (int)(x + 0.5); - while ((double)y < x - 0.5) y++; - while ((double)y > x + 0.5) y--; - return y; -} - inline static long -our_lround(double x) { - int y; +our_round(double x) { + long y; if (x > 0.0) y = x + 0.5; @@ -398,7 +389,7 @@ initiate_slew(void) if (fabs(offset_register) < MAX_ADJUST_WITH_ADJTIME) { /* Use adjtime to do the shift */ - offset = our_lround(1.0e6 * -offset_register); + offset = our_round(1.0e6 * -offset_register); offset_register += offset * 1e-6; -- 2.47.3