Permalink
Browse files

Merge pull request #481 from xen2/async_method_nullref

Protect against null reference exception when there is no yields in async methods
  • Loading branch information...
2 parents 4a5117a + 4cae8ff commit cd4100c92918ec9fbca97f8f0b56861e08fadcc8 @jbevain committed Jan 17, 2018
Showing with 6 additions and 4 deletions.
  1. +6 −4 Mono.Cecil/AssemblyWriter.cs
@@ -2408,10 +2408,12 @@ void AddAsyncMethodBodyDebugInformation (ICustomDebugInformationProvider provide
var signature = CreateSignatureWriter ();
signature.WriteUInt32 ((uint) async_method.catch_handler.Offset + 1);
- for (int i = 0; i < async_method.yields.Count; i++) {
- signature.WriteUInt32 ((uint) async_method.yields [i].Offset);
- signature.WriteUInt32 ((uint) async_method.resumes [i].Offset);
- signature.WriteCompressedUInt32 (async_method.resume_methods [i].MetadataToken.RID);
+ if (!async_method.yields.IsNullOrEmpty ()) {
+ for (int i = 0; i < async_method.yields.Count; i++) {
+ signature.WriteUInt32 ((uint) async_method.yields [i].Offset);
+ signature.WriteUInt32 ((uint) async_method.resumes [i].Offset);
+ signature.WriteCompressedUInt32 (async_method.resume_methods [i].MetadataToken.RID);
+ }
}
AddCustomDebugInformation (provider, async_method, signature);

0 comments on commit cd4100c

Please sign in to comment.