From 675809640360312406cae1e08107d84febf81fc3 Mon Sep 17 00:00:00 2001 From: Warner Losh Date: Sat, 13 Apr 2019 04:46:35 +0000 Subject: [PATCH] Fix sbttons for values > 2s Add test against negative times. Add code to cope with larger values properly. Discussed with: bde@ (quite some time ago, for an earlier version) --- sys/sys/time.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/sys/sys/time.h b/sys/sys/time.h index dbb5c9307232..4051b9d31657 100644 --- a/sys/sys/time.h +++ b/sys/sys/time.h @@ -184,8 +184,18 @@ sbttobt(sbintime_t _sbt) static __inline int64_t sbttons(sbintime_t _sbt) { + uint64_t ns; - return ((1000000000 * _sbt) >> 32); +#ifdef KASSERT + KASSERT(_sbt >= 0, ("Negative values illegal for sbttons: %jx", _sbt)); +#endif + ns = _sbt; + if (ns >= SBT_1S) + ns = (ns >> 32) * 1000000000; + else + ns = 0; + + return (ns + (1000000000 * (_sbt & 0xffffffffu) >> 32)); } static __inline sbintime_t