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

Submitted by:  Andrew Yates <andrewy>
Submitted on:  Sat 31 Dec 2005 11:27:22 PM UTC  
 
Category: NoneSeverity: 3 - Normal
Item Group: NoneStatus: Invalid
Privacy: PublicAssigned 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>
Project 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>

 

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
  • -unavailable- added by ktreichel (Posted a comment)
  •  

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 3 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Fri 25 May 2007 12:50:30 PM UTCktreichelStatusNone=>Invalid
      Open/ClosedOpen=>Closed
    Sat 31 Dec 2005 11:29:31 PM UTCandrewyAttached File-=>Added test.cs, #3234

    Back to the top


    Powered by Savane 3.1-cleanup1