Skip to content

Commit ede17f9

Browse files
authored
Fix handling of empty string constants (#776)
1 parent 04b4497 commit ede17f9

File tree

4 files changed

+20
-1
lines changed

4 files changed

+20
-1
lines changed

Mono.Cecil/AssemblyReader.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -3005,7 +3005,9 @@ ConstantDebugInformation ReadLocalConstant (uint rid)
30053005

30063006
object value;
30073007
if (type.etype == ElementType.String) {
3008-
if (signature.CanReadMore () && signature.buffer [signature.position] != 0xff) {
3008+
if (!signature.CanReadMore ())
3009+
value = "";
3010+
else if (signature.buffer [signature.position] != 0xff) {
30093011
var bytes = signature.ReadBytes ((int) (signature.sig_length - (signature.position - signature.start)));
30103012
value = Encoding.Unicode.GetString (bytes, 0, bytes.Length);
30113013
} else

Test/Mono.Cecil.Tests/PortablePdbTests.cs

+17
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,23 @@ public void GenericInstConstantRecord ()
474474
}
475475
}
476476

477+
[Test]
478+
public void EmptyStringLocalConstant ()
479+
{
480+
TestModule ("empty-str-const.exe", module => {
481+
var type = module.GetType ("<Program>$");
482+
var method = type.GetMethod ("<Main>$");
483+
var symbol = method.DebugInformation;
484+
485+
Assert.IsNotNull (symbol);
486+
Assert.AreEqual (1, symbol.Scope.Constants.Count);
487+
488+
var a = symbol.Scope.Constants [0];
489+
Assert.AreEqual ("value", a.Name);
490+
Assert.AreEqual ("", a.Value);
491+
}, symbolReaderProvider: typeof (PortablePdbReaderProvider), symbolWriterProvider: typeof (PortablePdbWriterProvider));
492+
}
493+
477494
[Test]
478495
public void SourceLink ()
479496
{
Binary file not shown.
2.61 KB
Binary file not shown.

0 commit comments

Comments
 (0)