From bf96da65540774a723e0712c49688939c930f635 Mon Sep 17 00:00:00 2001 From: Marek Safar Date: Tue, 9 Sep 2008 12:57:09 +0000 Subject: [PATCH] 2008-09-09 Marek Safar * Convert.cs, Decimal.cs: Fixed float/double to decimal range check. svn path=/trunk/mcs/; revision=112581 --- mcs/class/corlib/System/ChangeLog | 4 ++++ mcs/class/corlib/System/Convert.cs | 6 +----- mcs/class/corlib/System/Decimal.cs | 6 ++++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/mcs/class/corlib/System/ChangeLog b/mcs/class/corlib/System/ChangeLog index 662ae607aef..d00a3cee1e4 100644 --- a/mcs/class/corlib/System/ChangeLog +++ b/mcs/class/corlib/System/ChangeLog @@ -1,3 +1,7 @@ +2008-09-09 Marek Safar + + * Convert.cs, Decimal.cs: Fixed float/double to decimal range check. + 2008-09-07 Miguel de Icaza * TermInfoDriver.cs: Add support for updating the size of the diff --git a/mcs/class/corlib/System/Convert.cs b/mcs/class/corlib/System/Convert.cs index 2a1e09d4f09..8ccd85002b8 100644 --- a/mcs/class/corlib/System/Convert.cs +++ b/mcs/class/corlib/System/Convert.cs @@ -834,11 +834,7 @@ namespace System { public static decimal ToDecimal (double value) { - if (value > (double)Decimal.MaxValue || value < (double)Decimal.MinValue) - throw new OverflowException (Locale.GetText ( - "Value is greater than Decimal.MaxValue or less than Decimal.MinValue")); - - return (decimal)value; + return (decimal) value; } public static decimal ToDecimal (float value) diff --git a/mcs/class/corlib/System/Decimal.cs b/mcs/class/corlib/System/Decimal.cs index 5dd816eebb5..42990058777 100644 --- a/mcs/class/corlib/System/Decimal.cs +++ b/mcs/class/corlib/System/Decimal.cs @@ -178,7 +178,8 @@ namespace System public Decimal (float value) { - if (value > (float)Decimal.MaxValue || value < (float)Decimal.MinValue) { + if (value > (float)Decimal.MaxValue || value < (float)Decimal.MinValue || + float.IsNaN (value) || float.IsNegativeInfinity (value) || float.IsPositiveInfinity (value)) { throw new OverflowException (Locale.GetText ( "Value {0} is greater than Decimal.MaxValue or less than Decimal.MinValue", value)); } @@ -193,7 +194,8 @@ namespace System public Decimal (double value) { - if (value > (double)Decimal.MaxValue || value < (double)Decimal.MinValue) { + if (value > (double)Decimal.MaxValue || value < (double)Decimal.MinValue || + double.IsNaN (value) || double.IsNegativeInfinity (value) || double.IsPositiveInfinity (value)) { throw new OverflowException (Locale.GetText ( "Value {0} is greater than Decimal.MaxValue or less than Decimal.MinValue", value)); } -- 2.25.1