fix DateTime overflow on ARM32 (dotnet/coreclr#21902)
authorTomas Weinfurt <tweinfurt@yahoo.com>
Wed, 9 Jan 2019 10:53:35 +0000 (02:53 -0800)
committerJan Kotas <jkotas@microsoft.com>
Wed, 9 Jan 2019 10:53:35 +0000 (02:53 -0800)
Commit migrated from https://github.com/dotnet/coreclr/commit/3c81b68ca399f16077c159e838da38968494f3a7

src/libraries/System.Private.CoreLib/src/System/DateTime.cs

index c0210b0..a94171f 100644 (file)
@@ -455,10 +455,12 @@ namespace System
         // time units to this DateTime.
         private DateTime Add(double value, int scale)
         {
-            long millis = (long)(value * scale + (value >= 0 ? 0.5 : -0.5));
-            if (millis <= -MaxMillis || millis >= MaxMillis)
-                throw new ArgumentOutOfRangeException(nameof(value), SR.ArgumentOutOfRange_AddValue);
-            return AddTicks(millis * TicksPerMillisecond);
+            double millis_double = value * (double)scale + (value >= 0 ? 0.5 : -0.5);
+
+            if (millis_double <= (double)-MaxMillis || millis_double >= (double)MaxMillis)
+                 throw new ArgumentOutOfRangeException(nameof(value), SR.ArgumentOutOfRange_AddValue);
+
+            return AddTicks((long)millis_double * TicksPerMillisecond);
         }
 
         // Returns the DateTime resulting from adding a fractional number of