[Mono-bugs] [Bug 43098][Nor] New - Convert.ToUInt16 doesn't throw OverflowException (easy fix)

bugzilla-daemon@rocky.ximian.com bugzilla-daemon@rocky.ximian.com
Thu, 15 May 2003 15:38:34 -0400 (EDT)


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by c5n4kh6u02@sneakemail.com.

http://bugzilla.ximian.com/show_bug.cgi?id=43098

--- shadow/43098	Thu May 15 15:38:34 2003
+++ shadow/43098.tmp.24068	Thu May 15 15:38:34 2003
@@ -0,0 +1,47 @@
+Bug#: 43098
+Product: Mono/Class Libraries
+Version: unspecified
+OS: All
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Normal
+Component: CORLIB
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: c5n4kh6u02@sneakemail.com               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: Convert.ToUInt16 doesn't throw OverflowException (easy fix)
+
+In /mcs/class/corlib/System/Convert.cs :
+
+[CLSCompliant (false)]
+public static ushort ToUInt16 (string value, int fromBase) 
+{
+    return (ushort) ConvertFromBase (value, fromBase);
+} 
+
+This code does not throw an OverflowException for input values that are 
+outside the range of UInt16 but within the range of Int32. For example,
+
+ushort retVal = Convert.ToUInt16( "abcde", 16 );
+
+This call will succeed with a return value of 0xbcde instead of throwing 
+an OverflowException.
+
+I can see from the CVS log that the same bug was corrected in ToInt16 on 
+2002-06-02. The same fix is appropriate for ToUInt16:
+
+[CLSCompliant (false)]
+public static ushort ToUInt16 (string value, int fromBase) 
+{
+    return ToUInt16 (ConvertFromBase (value, fromBase));
+} 
+
+I took a cursory glance through the rest of Convert.cs to look for similar 
+problems and didn't see any. It would probably be wise to look more 
+thoroughly, however, and also add overflow tests to your regression test 
+suite.