Skip to content

Commit

Permalink
Fix handling of empty string constants (#776)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbevain authored Jul 2, 2021
1 parent 04b4497 commit ede17f9
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Mono.Cecil/AssemblyReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3005,7 +3005,9 @@ ConstantDebugInformation ReadLocalConstant (uint rid)

object value;
if (type.etype == ElementType.String) {
if (signature.CanReadMore () && signature.buffer [signature.position] != 0xff) {
if (!signature.CanReadMore ())
value = "";
else if (signature.buffer [signature.position] != 0xff) {
var bytes = signature.ReadBytes ((int) (signature.sig_length - (signature.position - signature.start)));
value = Encoding.Unicode.GetString (bytes, 0, bytes.Length);
} else
Expand Down
17 changes: 17 additions & 0 deletions Test/Mono.Cecil.Tests/PortablePdbTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,23 @@ public void GenericInstConstantRecord ()
}
}

[Test]
public void EmptyStringLocalConstant ()
{
TestModule ("empty-str-const.exe", module => {
var type = module.GetType ("<Program>$");
var method = type.GetMethod ("<Main>$");
var symbol = method.DebugInformation;

Assert.IsNotNull (symbol);
Assert.AreEqual (1, symbol.Scope.Constants.Count);

var a = symbol.Scope.Constants [0];
Assert.AreEqual ("value", a.Name);
Assert.AreEqual ("", a.Value);
}, symbolReaderProvider: typeof (PortablePdbReaderProvider), symbolWriterProvider: typeof (PortablePdbWriterProvider));
}

[Test]
public void SourceLink ()
{
Expand Down
Binary file added Test/Resources/assemblies/empty-str-const.exe
Binary file not shown.
Binary file added Test/Resources/assemblies/empty-str-const.pdb
Binary file not shown.

0 comments on commit ede17f9

Please sign in to comment.