From: Alan T. DeKok Date: Thu, 28 Oct 2021 12:51:04 +0000 (-0400) Subject: use scale function instead of inline code X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=35ce69f3884e8538377ef8ace059a33d4aed871c;p=thirdparty%2Ffreeradius-server.git use scale function instead of inline code the scale function also checks for overflow, and clamps the output. --- diff --git a/src/lib/util/value.c b/src/lib/util/value.c index 4bbbb8da3ca..3483332a399 100644 --- a/src/lib/util/value.c +++ b/src/lib/util/value.c @@ -1878,28 +1878,7 @@ ssize_t fr_value_box_from_network(TALLOC_CTX *ctx, FR_DBUFF_OUT_UINT64V_RETURN(&date, &work_dbuff, length); - switch (precision) { - case FR_TIME_RES_SEC: /* external seconds, internal nanoseconds */ - date *= NSEC; - break; - - case FR_TIME_RES_CSEC: - date *= (NSEC / CSEC); - break; - - case FR_TIME_RES_MSEC: - date *= (NSEC / MSEC); - break; - - case FR_TIME_RES_USEC: - date *= (NSEC / USEC); - break; - - case FR_TIME_RES_NSEC: - break; - } - - dst->vb_date = fr_unix_time_wrap(date); + dst->vb_date = fr_unix_time_wrap(fr_time_scale(date, precision)); } break;