diff --git a/src/libraries/System.Data.Odbc/src/Common/System/Data/Common/SafeNativeMethods.cs b/src/libraries/System.Data.Odbc/src/Common/System/Data/Common/SafeNativeMethods.cs deleted file mode 100644 index cf868366882b0..0000000000000 --- a/src/libraries/System.Data.Odbc/src/Common/System/Data/Common/SafeNativeMethods.cs +++ /dev/null @@ -1,21 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace System.Data -{ - internal static partial class SafeNativeMethods - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static unsafe void ZeroMemory(IntPtr ptr, int length) - { -#if !NET7_0_OR_GREATER - new Span((void*)ptr, length).Clear(); -#else - NativeMemory.Clear((void*)ptr, (uint)length); -#endif - } - } -} diff --git a/src/libraries/System.Data.Odbc/src/Common/System/Data/ProviderBase/DbBuffer.cs b/src/libraries/System.Data.Odbc/src/Common/System/Data/ProviderBase/DbBuffer.cs index 01be49419818a..541f1516eff59 100644 --- a/src/libraries/System.Data.Odbc/src/Common/System/Data/ProviderBase/DbBuffer.cs +++ b/src/libraries/System.Data.Odbc/src/Common/System/Data/ProviderBase/DbBuffer.cs @@ -16,6 +16,8 @@ internal abstract class DbBuffer : SafeHandle protected unsafe DbBuffer(int initialSize) : base(IntPtr.Zero, true) { + Debug.Assert(initialSize % IntPtr.Size == 0, $"Expected aligned {nameof(initialSize)}."); + if (0 < initialSize) { _bufferLength = initialSize; @@ -627,7 +629,7 @@ internal unsafe void WriteSingle(int offset, float value) WriteInt32(offset, BitConverter.SingleToInt32Bits(value)); } - internal void ZeroMemory() + internal unsafe void ZeroMemory() { bool mustRelease = false; @@ -636,7 +638,7 @@ internal void ZeroMemory() DangerousAddRef(ref mustRelease); IntPtr ptr = DangerousGetHandle(); - SafeNativeMethods.ZeroMemory(ptr, Length); + Unsafe.InitBlock((void*)ptr, 0, (uint)Length); } finally { diff --git a/src/libraries/System.Data.Odbc/src/System.Data.Odbc.csproj b/src/libraries/System.Data.Odbc/src/System.Data.Odbc.csproj index 56bcf649fcd4b..0bcb60c92da19 100644 --- a/src/libraries/System.Data.Odbc/src/System.Data.Odbc.csproj +++ b/src/libraries/System.Data.Odbc/src/System.Data.Odbc.csproj @@ -42,7 +42,6 @@ System.Data.Odbc.OdbcTransaction -