dotgnu-pnet
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Pnet-developers] [Bug #3487] Formatter.cs decimal padding passes negati


From: nobody
Subject: [Pnet-developers] [Bug #3487] Formatter.cs decimal padding passes negative arg to StringBuilder.Insert
Date: Wed, 07 May 2003 02:16:51 -0400

=================== BUG #3487: LATEST MODIFICATIONS ==================
http://savannah.gnu.org/bugs/?func=detailbug&bug_id=3487&group_id=353

Changes by: Gopal.V <address@hidden>
Date: Wed 05/07/2003 at 11:46 (Asia/Calcutta)

------------------ Additional Follow-up Comments ----------------------------
The patch has hit the CVS (under David Corking) , the question here is -- is 
anyone else behind the rest of the bug ?



=================== BUG #3487: FULL BUG SNAPSHOT ===================


Submitted by: dcorking                Project: DotGNU Portable.NET          
Submitted on: Wed 05/07/2003 at 00:43
Category:  None                       Severity:  5 - Major                  
Bug Group:  None                      Resolution:  None                     
Assigned to:  None                    Status:  Open                         

Summary:  Formatter.cs decimal padding passes negative arg to 
StringBuilder.Insert

Original Submission:  I hope that documenting this glitch is some use even 
though I am a newbie at pnetlib and in CLI in
general.

The following patch against pnetlib-0.5.4 to Formatter.cs works for me
at least.  It fixes what seems to be an incorrect call to
StringBuilder.Insert in the decimal string padding code in pnetlib.

(Sorry I couldn't test CVS or 0.5.6 ?bug #3467 - but the relevant code
 hasn't changed)

Please *do not commit* this patch to CVS - it is only to explain the
glitch I think I found - I don't know my way around the library sources so 
someone that does should make the definitive patch.

I have attached a tiny test program to demonstrate this.  Here is the runtime 
output before the patch

$ ilrun ./a.out.exe
Testing 0.00m - no format specifier
Testing 0.00m : N2
Uncaught exception: System.ArgumentOutOfRangeException: Value must not be negati
ve
Parameter name: count
        at System.Text.StringBuilder.Insert(Int32, String, Int32) in ./System/Te
xt/StringBuilder.cs:646
        at System.Private.NumberFormat.Formatter.FormatDecimal(Decimal) in ./Sys
tem/Private/NumberFormat/Formatter.cs:384
        at System.Private.NumberFormat.Formatter.FormatAnyRound(Object, Int32) i
n ./System/Private/NumberFormat/Formatter.cs:307
        at System.Private.NumberFormat.NumberFormatter.Format(Object, IFormatPro
vider) in ./System/Private/NumberFormat/NumberFormatter.cs:84
        at System.Decimal.ToString(String, IFormatProvider) in ./System/Decimal.
cs:322
        at System.Decimal.ToString(String) in ./System/Decimal.cs:313
        at DCorking.DecimalToStringTester.Main()

After the patch the test value 0.00m : N2 works correctly.  However some
of my other test values are causing different (int overflow) problems
which I haven't addressed

Here is the output from my little test program after the patch

$ ilrun ./a.out.exe
Testing 0.00m - no format specifier
Testing 0.00m : N2
Testing 1.00m - no format specifier
Testing 1234567899123456789912345678m - no format specifier
Uncaught exception: System.OverflowException: Valid Int32 values are between -21
47483648 and 2147483647, inclusive
        at System.Decimal.ToInt32(Decimal) in ./System/Decimal.cs:511
        at System.Decimal.op_Explicit(Decimal) in ./System/Decimal.cs:172
        at System.Private.NumberFormat.Formatter.FormatDecimal(Decimal) in ./Sys
tem/Private/NumberFormat/Formatter.cs:376
        at System.Private.NumberFormat.Formatter.FormatAnyRound(Object, Int32) i
n ./System/Private/NumberFormat/Formatter.cs:307
        at System.Private.NumberFormat.FixedPointFormatter.Format(Object, IForma
tProvider) in ./System/Private/NumberFormat/FixedPointFormatter.cs:43
        at System.Private.NumberFormat.GeneralFormatter.Format(Object, IFormatPr
ovider) in ./System/Private/NumberFormat/GeneralFormatter.cs:121
        at System.Decimal.ToString(String, IFormatProvider) in ./System/Decimal.
cs:322
        at System.Decimal.ToString() in ./System/Decimal.cs:309
        at DCorking.DecimalToStringTester.Main()

Finally here is the successful output from the same executable with
runtime from another vendor.  My program looks correct to my eyes:

$ ./a.out.exe
Testing 0.00m - no format specifier
Testing 0.00m : N2
Testing 1.00m - no format specifier
Testing 1234567899123456789912345678m - no format specifier
Testing 1234567899123456789912345678m : N2
If no exceptions so far, then all tests passed.

My three tests were done under cygwin on W2K SP3.

Inline below is the patch and an incomplete test procedure

diff --unified --recursive 
pnetlib-0.5.4original/runtime/System/Private/NumberFormat/Formatter.cs 
pnetlib-0.5.4/runtime/System/Private/NumberFormat/Formatter.cs
--- pnetlib-0.5.4original/runtime/System/Private/NumberFormat/Formatter.cs      
2003-03-29 04:44:51.000000000 -0500
+++ pnetlib-0.5.4/runtime/System/Private/NumberFormat/Formatter.cs      
2003-05-04 08:13:04.000000000 -0400
@@ -381,7 +381,7 @@
                //  Pad out significant digits
                if (ret.Length < scale) 
                {
-                       ret.Insert(0, "0", ret.Length - scale);
+                       ret.Insert(0, "0", scale - ret.Length);
                }
 
                //  Insert a decimal point

I hope line wrapping hasn't garbled this too badly.



Follow-up Comments
*******************

-------------------------------------------------------
Date: Wed 05/07/2003 at 11:46       By: t3rmin4t0r
The patch has hit the CVS (under David Corking) , the question here is -- is 
anyone else behind the rest of the bug ?


CC list is empty


File Attachments
****************

-------------------------------------------------------
Date: Wed 05/07/2003 at 00:43  Name: DecimalToStringGlitch.cs  Size: 0KB   By: 
dcorking
simple test to demonstrate glitch
http://savannah.gnu.org/bugs/download.php?group_id=353&amp;bug_id=3487&amp;bug_file_id=431


For detailed info, follow this link:
http://savannah.gnu.org/bugs/?func=detailbug&bug_id=3487&group_id=353


reply via email to

[Prev in Thread] Current Thread [Next in Thread]