1
0
mirror of https://github.com/openbsd/src.git synced 2026-06-18 15:23:33 +02:00

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
This commit is contained in:
millert
2026-04-23 01:08:47 +00:00
parent 9c4709afbf
commit b018fffbd6
+3 -3
View File
@@ -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)