Skip to content
This repository has been archived by the owner on Jan 14, 2021. It is now read-only.

Commit

Permalink
Fix #1484: Add null check when converting arguments.
Browse files Browse the repository at this point in the history
  • Loading branch information
baulig committed Aug 21, 2012
1 parent 20f2d81 commit ff349f1
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/ObjCRuntime/NativeImplementationBuilder.cs
Expand Up @@ -191,22 +191,46 @@ internal abstract class NativeImplementationBuilder {
#if !MONOMAC_BOOTSTRAP
for (int i = ArgumentOffset, j = 0; i < ParameterTypes.Length; i++) {
if (Parameters [i-ArgumentOffset].ParameterType.IsByRef && (Attribute.GetCustomAttribute (Parameters [i-ArgumentOffset], typeof (OutAttribute)) == null) && IsWrappedType (Parameters[i-ArgumentOffset].ParameterType.GetElementType ())) {
var nullout = il.DefineLabel ();
var done = il.DefineLabel ();
il.Emit (OpCodes.Ldarg, i);
il.Emit (OpCodes.Brfalse, nullout);
il.Emit (OpCodes.Ldarg, i);
il.Emit (OpCodes.Ldind_I);
il.Emit (OpCodes.Call, getobject);
il.Emit (OpCodes.Br, done);
il.MarkLabel (nullout);
il.Emit (OpCodes.Ldnull);
il.MarkLabel (done);
il.Emit (OpCodes.Stloc, j+locoffset);
j++;
} else if (Parameters [i-ArgumentOffset].ParameterType.IsArray && IsWrappedType (Parameters [i-ArgumentOffset].ParameterType.GetElementType ())) {
var nullout = il.DefineLabel ();
var done = il.DefineLabel ();
il.Emit (OpCodes.Ldarg, i);
il.Emit (OpCodes.Brfalse, nullout);
il.Emit (OpCodes.Ldarg, i);
if (Parameters [i-ArgumentOffset].ParameterType.GetElementType () == typeof (string))
il.Emit (OpCodes.Call, convertsarray);
else
il.Emit (OpCodes.Call, convertarray.MakeGenericMethod (Parameters [i-ArgumentOffset].ParameterType.GetElementType ()));
il.Emit (OpCodes.Br, done);
il.MarkLabel (nullout);
il.Emit (OpCodes.Ldnull);
il.MarkLabel (done);
il.Emit (OpCodes.Stloc, j+locoffset);
j++;
} else if (Parameters [i-ArgumentOffset].ParameterType == typeof (string)) {
var nullout = il.DefineLabel ();
var done = il.DefineLabel ();
il.Emit (OpCodes.Ldarg, i);
il.Emit (OpCodes.Brfalse, nullout);
il.Emit (OpCodes.Ldarg, i);
il.Emit (OpCodes.Call, convertstring);
il.Emit (OpCodes.Br, done);
il.MarkLabel (nullout);
il.Emit (OpCodes.Ldnull);
il.MarkLabel (done);
il.Emit (OpCodes.Stloc, j+locoffset);
j++;
}
Expand Down

0 comments on commit ff349f1

Please sign in to comment.