From f8bf7e5da4976c7123f4889fd77b67ca6f0011bb Mon Sep 17 00:00:00 2001 From: Albrecht Schlosser Date: Tue, 3 Oct 2023 16:37:59 +0200 Subject: Avoid integer overflow on Windows in delta time calculation See comment in the code. This makes the implementation more future proof although it's still problematic starting around 2038. --- src/Fl_Timeout.cxx | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/Fl_Timeout.cxx b/src/Fl_Timeout.cxx index 50445eec6..790beaa99 100644 --- a/src/Fl_Timeout.cxx +++ b/src/Fl_Timeout.cxx @@ -19,7 +19,6 @@ #include "Fl_System_Driver.H" #include -#include // for LONG_MIN /** \file Fl_Timeout.cxx @@ -80,10 +79,21 @@ Fl_Timestamp Fl::now() { return ts; // C++ will copy the result into the lvalue for us } -/** The time stamp of a time point in the distant past */ +/** The time stamp of a time point in the distant past. + + This point in time is unspecified and may be changed in a later + FLTK version. + + \internal + Implementation notes: + - Currently Fl_Timestamp is based on the "Unix Epoch", i.e. 0 (zero) + is equivalent to Jan 1, 1970 00:00 UTC. This may change in the future. + - Setting the value of Fl::distant_past() to 0 (zero) avoids integer + overflow if sizeof(long) == 4 (Windows), at least until 2038. +*/ const Fl_Timestamp Fl::distant_past() { Fl_Timestamp ts; - ts.sec = LONG_MIN/10; + ts.sec = 0; ts.usec = 0; return (const Fl_Timestamp)ts; } -- cgit v1.2.3