Skip to content

Commit 2304f5e

Browse files
committed
Fix tests on .NET Framework.
We must increment the pointers after we write the bytes.
1 parent b0d2baa commit 2304f5e

File tree

1 file changed

+9
-6
lines changed
  • src/libraries/System.Reflection.Metadata/src/System/Reflection/Internal/Utilities

1 file changed

+9
-6
lines changed

src/libraries/System.Reflection.Metadata/src/System/Reflection/Internal/Utilities/BlobUtilities.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -172,14 +172,15 @@ public static unsafe void WriteUtf8(ReadOnlySpan<char> source, Span<byte> destin
172172

173173
while (src < srcEnd)
174174
{
175-
char c = *src++;
175+
char c = *src;
176176
if (c < 0x80)
177177
{
178178
if (dstEnd - dst < 1)
179179
{
180180
break;
181181
}
182182
*dst++ = (byte)c;
183+
src++;
183184
}
184185
else if (c < 0x7FF)
185186
{
@@ -189,15 +190,15 @@ public static unsafe void WriteUtf8(ReadOnlySpan<char> source, Span<byte> destin
189190
}
190191
*dst++ = (byte)((c >> 6) | 0xC0);
191192
*dst++ = (byte)((c & 0x3F) | 0x80);
193+
src++;
192194
}
193195
else
194196
{
195197
if (char.IsSurrogate(c))
196198
{
197199
// surrogate pair
198-
if (char.IsHighSurrogate(c) && src < srcEnd && *src is char cLow && char.IsLowSurrogate(cLow))
200+
if (char.IsHighSurrogate(c) && src - srcEnd < 2 && src[1] is char cLow && char.IsLowSurrogate(cLow))
199201
{
200-
src++;
201202
if (dstEnd - dst < 4)
202203
{
203204
break;
@@ -207,6 +208,7 @@ public static unsafe void WriteUtf8(ReadOnlySpan<char> source, Span<byte> destin
207208
*dst++ = (byte)(((codepoint >> 12) & 0x3F) | 0x80);
208209
*dst++ = (byte)(((codepoint >> 6) & 0x3F) | 0x80);
209210
*dst++ = (byte)((codepoint & 0x3F) | 0x80);
211+
src += 2;
210212
continue;
211213
}
212214

@@ -224,12 +226,13 @@ public static unsafe void WriteUtf8(ReadOnlySpan<char> source, Span<byte> destin
224226
*dst++ = (byte)((c >> 12) | 0xE0);
225227
*dst++ = (byte)(((c >> 6) & 0x3F) | 0x80);
226228
*dst++ = (byte)((c & 0x3F) | 0x80);
229+
src++;
227230
}
228231
}
229-
}
230232

231-
charsRead = sourceLength - source.Length;
232-
bytesWritten = destinationLength - destination.Length;
233+
charsRead = (int)(src - pSource);
234+
bytesWritten = (int)(dst - pDestination);
235+
}
233236
}
234237
#endif
235238

0 commit comments

Comments
 (0)