summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlbrecht Schlosser <albrechts.fltk@online.de>2023-10-03 16:37:59 +0200
committerAlbrecht Schlosser <albrechts.fltk@online.de>2023-10-03 16:37:59 +0200
commitf8bf7e5da4976c7123f4889fd77b67ca6f0011bb (patch)
tree9eda28dd842abf0d5baddbaa03c08a7670121ebe /src
parentcfa1a3bd401cea0e2cc9a5172971c28ead7dcfff (diff)
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.
Diffstat (limited to 'src')
-rw-r--r--src/Fl_Timeout.cxx16
1 files changed, 13 insertions, 3 deletions
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 <stdio.h>
-#include <limits.h> // 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;
}