diff --git a/ntp_core.c b/ntp_core.c index 8987468..26ca39b 100644 --- a/ntp_core.c +++ b/ntp_core.c @@ -1404,8 +1404,7 @@ receive_packet(NTP_Packet *message, struct timeval *now, double now_err, NCR_Ins &sample_time, offset, delay, dispersion, root_delay, root_dispersion, - message->stratum > inst->min_stratum ? - message->stratum : inst->min_stratum, + MAX(message->stratum, inst->min_stratum), (NTP_Leap) pkt_leap); SRC_SelectSource(inst->source); diff --git a/util.h b/util.h index 78b7d71..ebd0d20 100644 --- a/util.h +++ b/util.h @@ -148,4 +148,17 @@ extern int UTI_CheckDirPermissions(const char *path, mode_t perm, uid_t uid, gid /* Fill buffer with random bytes */ extern void UTI_GetRandomBytes(void *buf, unsigned int len); +/* Macros to get maximum and minimum of two values */ +#ifdef MAX +#undef MAX +#endif +#define MAX(x, y) ((x) > (y) ? (x) : (y)) +#ifdef MIN +#undef MIN +#endif +#define MIN(x, y) ((x) < (y) ? (x) : (y)) + +/* Macro to clamp a value between two values */ +#define CLAMP(min, x, max) (MAX((min), MIN((x), (max)))) + #endif /* GOT_UTIL_H */