cy 2a19333fd4 MFV r358616:
Update ntp-4.2.8p13 --> 4.2.8p14.

The advisory can be found at:
http://support.ntp.org/bin/view/Main/SecurityNotice#\
March_2020_ntp_4_2_8p14_NTP_Rele

No CVEs have been documented yet.

MFC after:	now
Security:	http://support.ntp.org/bin/view/Main/NtpBug3610
		http://support.ntp.org/bin/view/Main/NtpBug3596
		http://support.ntp.org/bin/view/Main/NtpBug3592
2020-03-04 21:45:12 +00:00

84 lines
1.2 KiB
C

/*
* timexsup.c - 'struct timex' support functions
*
* Written by Juergen Perlinger (perlinger@ntp.org) for the NTP project.
* The contents of 'html/copyright.html' apply.
*/
#include "config.h"
#include "timexsup.h"
#include <limits.h>
#include <math.h>
#ifdef HAVE_SYS_TIMEX_H
# include <sys/timex.h>
#endif
#if defined(MOD_NANO) != defined(STA_NANO)
# warning inconsistent definitions of MOD_NANO vs STA_NANO
#endif
static long
clamp_rounded(
double dval
)
{
/* round */
dval = floor(dval + 0.5);
/* clamp / saturate */
if (dval >= LONG_MAX)
return LONG_MAX;
if (dval <= LONG_MIN)
return LONG_MIN;
return (long)dval;
}
double
dbl_from_var_long(
long lval,
int status
)
{
#ifdef STA_NANO
if (status & STA_NANO)
return (double)lval * 1e-9;
#else
(void)status;
#endif
return (double)lval * 1e-6;
}
double
dbl_from_usec_long(
long lval
)
{
return (double)lval * 1e-6;
}
long
var_long_from_dbl(
double dval,
unsigned int * modes
)
{
#ifdef MOD_NANO
*modes |= MOD_NANO;
dval *= 1e+9;
#else
(void)modes;
dval *= 1e+6;
#endif
return clamp_rounded(dval);
}
long
usec_long_from_dbl(
double dval
)
{
return clamp_rounded(dval * 1e+6);
}