Skip to content

Commit 3a13d5a

Browse files
ds5678siegfriedpammer
authored andcommitted
Allow explicit null termination character
1 parent 38cdf6d commit 3a13d5a

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,7 @@ private static TypeC TestC()
447447
#endif
448448
#if CS110 && !NET40
449449
public static ReadOnlySpan<byte> UTF8Literal => "Hello, world!"u8;
450+
public static ReadOnlySpan<byte> UTF8LiteralWithNullTerminator => "Hello, world!\0"u8;
450451
#endif
451452
#endregion
452453

ICSharpCode.Decompiler/IL/Transforms/TransformArrayInitializers.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,13 @@ private static unsafe bool DecodeUTF8String(BlobReader blob, int size, out strin
182182
for (int i = 0; i < size; i++)
183183
{
184184
byte val = blob.CurrentPointer[i];
185-
// If the string has control characters, it's probably binary data and not a string.
186-
if (val < 0x20 && val is not ((byte)'\r' or (byte)'\n' or (byte)'\t'))
185+
if (val == 0 && i == size - 1 && size > 1)
187186
{
187+
// Allow explicit null-termination character.
188+
}
189+
else if (val < 0x20 && val is not ((byte)'\r' or (byte)'\n' or (byte)'\t'))
190+
{
191+
// If the string has control characters, it's probably binary data and not a string.
188192
text = null;
189193
return false;
190194
}

0 commit comments

Comments
 (0)