Skip to content

Commit 8a295e8

Browse files
committed
argument checking
1 parent 33654ea commit 8a295e8

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

Mono.Reflection/ILPattern.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,11 @@ public bool TryMatch (MatchContext context)
164164

165165
public static MatchContext Match (MethodBase method, ILPattern pattern)
166166
{
167+
if (method == null)
168+
throw new ArgumentNullException ("method");
169+
if (pattern == null)
170+
throw new ArgumentNullException ("pattern");
171+
167172
var instructions = method.GetInstructions ();
168173
if (instructions.Count == 0)
169174
throw new ArgumentException ();
@@ -174,7 +179,7 @@ public static MatchContext Match (MethodBase method, ILPattern pattern)
174179
}
175180
}
176181

177-
public class MatchContext {
182+
public sealed class MatchContext {
178183

179184
internal Instruction instruction;
180185
internal bool success;
@@ -186,7 +191,7 @@ public bool IsMatch {
186191
set { success = true; }
187192
}
188193

189-
public MatchContext (Instruction instruction)
194+
internal MatchContext (Instruction instruction)
190195
{
191196
Reset (instruction);
192197
}

Mono.Reflection/Image.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
namespace Mono.Reflection {
3333

34-
public class Image : IDisposable {
34+
public sealed class Image : IDisposable {
3535

3636
long position;
3737
Stream stream;
@@ -102,14 +102,25 @@ bool IsManagedAssembly ()
102102

103103
public static bool IsAssembly (string file)
104104
{
105+
if (file == null)
106+
throw new ArgumentNullException ("file");
107+
105108
using (var stream = new FileStream (file, FileMode.Open, FileAccess.Read, FileShare.Read))
106109
return IsAssembly (stream);
107110
}
108111

109112
public static bool IsAssembly (Stream stream)
110113
{
114+
if (stream == null)
115+
throw new ArgumentNullException ("stream");
116+
if (!stream.CanRead)
117+
throw new ArgumentException ("Can not read from stream");
118+
if (!stream.CanSeek)
119+
throw new ArgumentException ("Can not seek in stream");
120+
111121
using (var image = new Image (stream))
112122
return image.IsManagedAssembly ();
113123
}
114124
}
115125
}
126+

Mono.Reflection/MethodBodyReader.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@ static MethodBodyReader ()
7474

7575
this.body = method.GetMethodBody ();
7676
if (this.body == null)
77-
throw new ArgumentException ();
77+
throw new ArgumentException ("Method has no body");
7878

7979
var bytes = body.GetILAsByteArray ();
8080
if (bytes == null)
81-
throw new ArgumentException ();
81+
throw new ArgumentException ("Can not get the body of the method");
8282

8383
if (!(method is ConstructorInfo))
8484
method_arguments = method.GetGenericArguments ();

0 commit comments

Comments
 (0)