From b018fffbd6c97a22e7af2d20e7fa5ba61fdbfb36 Mon Sep 17 00:00:00 2001 From: millert Date: Thu, 23 Apr 2026 01:08:47 +0000 Subject: [PATCH] Fix difftime() result when it is passed a negative value We need to cast the result of bitwise AND to time_t before the cast to double in the HI and LO macros. Otherwise, we get a very large positive floating point value instead of a negative value. Reported by Xuntao Chi --- lib/libc/time/difftime.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/libc/time/difftime.c b/lib/libc/time/difftime.c index 6d0140088b4..e62d5295469 100644 --- a/lib/libc/time/difftime.c +++ b/lib/libc/time/difftime.c @@ -1,10 +1,10 @@ -/* $OpenBSD: difftime.c,v 1.13 2025/05/21 01:27:29 millert Exp $ */ +/* $OpenBSD: difftime.c,v 1.14 2026/04/23 01:08:47 millert Exp $ */ /* This file is placed in the public domain by Matthew Dempsky. */ #include "private.h" -#define HI(t) ((double)(t & 0xffffffff00000000LL)) -#define LO(t) ((double)(t & 0x00000000ffffffffLL)) +#define HI(t) ((double)(time_t)(t & 0xffffffff00000000LL)) +#define LO(t) ((double)(time_t)(t & 0x00000000ffffffffLL)) double __pure difftime(time_t t1, time_t t0)