aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArnaud Charlet <charlet@adacore.com>2020-11-04 08:58:47 -0500
committerPierre-Marie de Rodat <derodat@adacore.com>2020-11-27 04:15:57 -0500
commit7d4ee5f8e2ab894fdeaa67824eb32103cda947f8 (patch)
tree786060e3ee1d23174c4239bc686810b68f9da15a
parent23e3e22105723fde2a9161757611544f180ba805 (diff)
downloadgcc-7d4ee5f8e2ab894fdeaa67824eb32103cda947f8.zip
gcc-7d4ee5f8e2ab894fdeaa67824eb32103cda947f8.tar.gz
gcc-7d4ee5f8e2ab894fdeaa67824eb32103cda947f8.tar.bz2
[Ada] To_GM_Time returning invalid value for Invalid_Time
gcc/ada/ * libgnat/s-os_lib.adb (To_GM_Time): Return valid and consistent values for Invalid_Time.
-rw-r--r--gcc/ada/libgnat/s-os_lib.adb25
1 files changed, 24 insertions, 1 deletions
diff --git a/gcc/ada/libgnat/s-os_lib.adb b/gcc/ada/libgnat/s-os_lib.adb
index 288325c..93522bc 100644
--- a/gcc/ada/libgnat/s-os_lib.adb
+++ b/gcc/ada/libgnat/s-os_lib.adb
@@ -1365,6 +1365,21 @@ package body System.OS_Lib is
S : Integer;
begin
+ -- Special case Invalid_Time which is handled differently between
+ -- Windows and Linux: Linux will set to 1 second before 1970-01-01
+ -- while Windows will set the time to 1970-01-01 with Second set to -1,
+ -- which is not a valid value.
+
+ if Date = Invalid_Time then
+ Year := 1969;
+ Month := 12;
+ Day := 31;
+ Hour := 23;
+ Minute := 59;
+ Second := 59;
+ return;
+ end if;
+
-- Use the global lock because To_GM_Time is not thread safe
Locked_Processing : begin
@@ -1387,7 +1402,15 @@ package body System.OS_Lib is
Year := Y + 1900;
Month := Mo + 1;
- Day := D;
+
+ -- May happen if To_GM_Time fails
+
+ if D = 0 then
+ Day := 1;
+ else
+ Day := D;
+ end if;
+
Hour := H;
Minute := Mn;
Second := S;