kern_ntptime: Fix undefined behavior of the shift operator

L_LINT macro is used with negative numbers [i.e.
L_LINT(time_freq, -MAXFREQ)], it could cause undefined
behavior. It should be similar to the L_RSHIFT(v, n) macro.

MFC after:	2 weeks
Reviewed by:	cy
Pull Request:	https://github.com/freebsd/freebsd-src/pull/769
Signed-off-by: Dmitriy Alexandrov <d06alexandrov@gmail.com>
This commit is contained in:
Dmitriy Alexandrov 2023-06-08 12:08:46 +03:00 committed by Cy Schubert
parent 2c01176a28
commit af9ce4e9bb

View File

@ -73,7 +73,13 @@ typedef int64_t l_fp;
#define L_MPY(v, a) ((v) *= (a))
#define L_CLR(v) ((v) = 0)
#define L_ISNEG(v) ((v) < 0)
#define L_LINT(v, a) ((v) = (int64_t)(a) << 32)
#define L_LINT(v, a) \
do { \
if ((a) < 0) \
((v) = -((int64_t)(-(a)) << 32)); \
else \
((v) = (int64_t)(a) << 32); \
} while (0)
#define L_GINT(v) ((v) < 0 ? -(-(v) >> 32) : (v) >> 32)
/*