[Mono-bugs] [Bug 398325] New: [PATCH] Use of unassigned local variable not recognized for variables declared after end of scope of an assigned variable
bugzilla_noreply at novell.com
bugzilla_noreply at novell.com
Sat Jun 7 22:39:28 EDT 2008
https://bugzilla.novell.com/show_bug.cgi?id=398325
Summary: [PATCH] Use of unassigned local variable not recognized
for variables declared after end of scope of an assigned
variable
Product: Mono: Compilers
Version: SVN
Platform: x86-64
OS/Version: Windows Vista
Status: NEW
Keywords: patch
Severity: Normal
Priority: P5 - None
Component: C#
AssignedTo: mono-bugs at lists.ximian.com
ReportedBy: Moritz.Kroll at gmx.de
QAContact: mono-bugs at lists.ximian.com
Found By: ---
Description of Problem:
The following code compiles without an error:
class test
{
static void Main(string[] args)
{
{
int x = 8;
}
string y;
args[0] = y; // use of unassigned variable y
}
}
This happens for two reasons:
- The UsageVector is not shortened to the number of variables available in the
outer block, when a flow branching ends, and
- when a MyBitVector is inherited from a smaller vector which inherits from a
larger vector, the values of the old larger vector are used instead of false
values.
Fix:
Index: flowanalysis.cs
===================================================================
--- flowanalysis.cs (revision 105252)
+++ flowanalysis.cs (working copy)
@@ -287,6 +287,11 @@
return new UsageVector (locals, is_unreachable,
null, loc);
}
+ public void Shorten (int newSize)
+ {
+ locals = locals.Shorten (newSize);
+ }
+
// <summary>
// Merges a child branching.
// </summary>
@@ -406,7 +411,9 @@
public UsageVector MergeChild (FlowBranching child)
{
- return CurrentUsageVector.MergeChild (child.Merge (),
true);
+ UsageVector result = CurrentUsageVector.MergeChild
(child.Merge (), true);
+ CurrentUsageVector.Shorten
(CurrentUsageVector.CountLocals);
+ return result;
}
public virtual bool CheckRethrow (Location loc)
@@ -1556,10 +1563,21 @@
public MyBitVector (MyBitVector InheritsFrom, int Count)
{
+ this.Count = Count;
+
if (InheritsFrom != null)
- shared = InheritsFrom.Shared;
-
- this.Count = Count;
+ {
+ if (Count > InheritsFrom.Count)
+ {
+ // Create a new larger vector and
initialize lower bits with InheritsFrom
+ // and rest with false
+ for (int i = 0; i < InheritsFrom.Count;
i++)
+ this[i] = InheritsFrom[i];
+ for (int i = InheritsFrom.Count; i <
Count; i++)
+ this[i] = false;
+ }
+ else shared = InheritsFrom.Shared;
+ }
}
// Use this accessor to get a shareable copy of the underlying
BitArray representation
@@ -1602,6 +1620,21 @@
}
// <summary>
+ // Shortens the bit vector to the given number of bits.
+ // An exception is thrown if the new number of bits is
greater than the current.
+ // </summary>
+ public MyBitVector Shorten (int newCount)
+ {
+ if (newCount > Count)
+ throw new ArgumentOutOfRangeException ();
+
+ if (newCount == Count)
+ return this;
+
+ return new MyBitVector (this, newCount);
+ }
+
+ // <summary>
// Performs an `or' operation on the bit vector. The
`new_vector' may have a
// different size than the current one.
// </summary>
--
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.
More information about the mono-bugs
mailing list