Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan McGovern <alan.mcgovern@gmail.com>2011-10-26 14:25:22 +0400
committerAlan McGovern <alan.mcgovern@gmail.com>2011-10-26 14:26:56 +0400
commit5f2835f2353b5cc7553135e02313c79b2d2464ac (patch)
tree3da373e20160400fa5ff682047ca5b007cc12555 /main/src/addins/prj2make-sharp-lib
parentd11c606e5b8568c4fd3366d6f6d32a1ec556b8f9 (diff)
[prj2make] Fix a crasher when opening an empty file
VS2003ProjectFileFormat was throwing an exception if the user selected a 0-byte file as 'null' was being passed to the regex. Fixes bug #1673.
Diffstat (limited to 'main/src/addins/prj2make-sharp-lib')
-rw-r--r--main/src/addins/prj2make-sharp-lib/VS2003ProjectFileFormat.cs26
1 files changed, 7 insertions, 19 deletions
diff --git a/main/src/addins/prj2make-sharp-lib/VS2003ProjectFileFormat.cs b/main/src/addins/prj2make-sharp-lib/VS2003ProjectFileFormat.cs
index 6c3fab9e8b..192a90f3a9 100644
--- a/main/src/addins/prj2make-sharp-lib/VS2003ProjectFileFormat.cs
+++ b/main/src/addins/prj2make-sharp-lib/VS2003ProjectFileFormat.cs
@@ -208,26 +208,14 @@ namespace MonoDevelop.Prj2Make
// Utility function to determine the sln file version
string GetSlnFileVersion(string strInSlnFile)
{
- string strVersion = null;
- string strInput = null;
- Match match;
- StreamReader reader = new StreamReader(strInSlnFile);
- strInput = reader.ReadLine();
-
- match = SlnMaker.SlnVersionRegex.Match(strInput);
- if (!match.Success) {
- match = SlnMaker.SlnVersionRegex.Match (reader.ReadLine ());
- }
-
- if (match.Success)
- {
- strVersion = match.Groups[1].Value;
+ using (var stream = File.OpenText (strInSlnFile)) {
+ // ReadLine returns null at EOF which makes the regex throw an ArgNull exception
+ var match = SlnMaker.SlnVersionRegex.Match (stream.ReadLine () ?? "");
+ if (!match.Success)
+ match = SlnMaker.SlnVersionRegex.Match (stream.ReadLine () ?? "");
+
+ return match.Success ? match.Groups[1].Value : null;
}
-
- // Close the stream
- reader.Close();
-
- return strVersion;
}
public bool SupportsMixedFormats {