bugDotGNU Portable.NET - Bugs: bug #15345, strings created in a while loop...

 
 

You are not allowed to post comments on this tracker with your current authentication level.

bug #15345: strings created in a while loop are not made null each iteration

Submitter:  Andrew Yates <andrewy>
Submitted:  Sat 31 Dec 2005 11:27:22 PM UTC
   
 
Category:  None Severity:  3 - Normal
Item Group:  None Status:  Invalid
Privacy:  Public Assigned to:  None
Open/Closed:  Closed

Fri 25 May 2007 12:50:30 PM UTC, comment #2: 

This is a problem that cscc doesn't check is the value is initialized before it's used. The behavior is is totally correct because you'll have to initialize test yourself.

Klaus Treichel <ktreichel>
Group administrator
Sat 31 Dec 2005 11:29:31 PM UTC, comment #1: 

I'm attaching the test code as the formatting was removed and this makes it more difficult to understand.

Andrew Yates <andrewy>
Sat 31 Dec 2005 11:27:22 PM UTC, original submission:  

Strings (and probably every other type) created in a while loop are not made null each iteration. Instead, their value is preserved across iterations.
I don't claim to be a C# expert, but it is my understanding that they should be made null each iteration.

Consider the following code:

public class adsf {
  static void Main() {
    int a=0;
    while (a<=3) {
      string test;
      test += a.ToString();
      Console.WriteLine("{0}", test);
      a++;
    }
  }
}

This compiles fine with cscc, and gives this output:
0
01
012
0123

As you can see, the value of the string "test" is preserved across iterations. csc or mcs both refuse to compile this code unless the line is changed to: string test = ""

Regardless of whether or not cscc lets it compile, I believe that  the string should be set to null every iteration.

Andrew Yates <andrewy>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attached Files
file #2293:  test.cs added by andrewy (195B - text/x-csharp - test code)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by ktreichel (Posted a comment)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

     

    Follow 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2007-05-25 ktreichel StatusNone Invalid
        Open/ClosedOpen Closed
    2005-12-31 andrewy Attached File- Added test.cs, #3234

    Back to the top

    Powered by Savane 3.13-4b48.
    Corresponding source code