From 725cf8f41780a6690627a11f4eb8ee4d15aad7ca Mon Sep 17 00:00:00 2001 From: Anna Date: Wed, 11 Dec 2024 17:27:37 +0100 Subject: [PATCH] remove unsafe with span --- .../AspNetCore/UserEvents/UserEventsCommon.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/AspNetCore/UserEvents/UserEventsCommon.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/AspNetCore/UserEvents/UserEventsCommon.cs index 18f3a00a71a6..6976922a6887 100644 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/AspNetCore/UserEvents/UserEventsCommon.cs +++ b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/AspNetCore/UserEvents/UserEventsCommon.cs @@ -23,7 +23,7 @@ internal static class UserEventsCommon internal static string? GetLogin(IIdentityUser? user) => user?.UserName ?? user?.Email; - internal static unsafe string Anonymize(string id) + internal static string Anonymize(string id) { // spec says take first half of the hash const int bytesToUse = 16; @@ -44,7 +44,7 @@ internal static unsafe string Anonymize(string id) // we want to end up with a string of the form anon_0c76692372ebf01a7da6e9570fb7d0a1 // 37 is 5 prefix character plus 32 hexadecimal digits (presenting 16 bytes) // stackalloc to avoid intermediate heap allocation - var stringChars = stackalloc char[37]; + Span stringChars = stackalloc char[37]; stringChars[0] = 'a'; stringChars[1] = 'n'; stringChars[2] = 'o'; @@ -58,7 +58,7 @@ internal static unsafe string Anonymize(string id) stringChars[iChars + 6] = ByteDigitToChar(b & 0x0F); } - return new string(stringChars, 0, 37); + return new string(stringChars.ToArray(), 0, 37); } Log.Debug("Couldn't anonymize user information (login or id), byteArray length was {BytesWritten}", bytesWritten);