diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlDataReader.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlDataReader.cs index 75f17d565f..7681520031 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlDataReader.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlDataReader.cs @@ -2046,7 +2046,7 @@ private bool TryGetBytesInternal(int i, long dataIndex, byte[] buffer, int buffe cbytes = length; } - Array.Copy(data, ndataIndex, buffer, bufferIndex, cbytes); + Buffer.BlockCopy(data, ndataIndex, buffer, bufferIndex, cbytes); } catch (Exception e) { diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlDelegatedTransaction.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlDelegatedTransaction.cs index a72605e86e..bf7f86c3a7 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlDelegatedTransaction.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlDelegatedTransaction.cs @@ -585,7 +585,7 @@ private void ValidateActiveOnConnection(SqlInternalConnection connection) private Guid GetGlobalTxnIdentifierFromToken() { byte[] txnGuid = new byte[16]; - Array.Copy(_connection.PromotedDTCToken, _globalTransactionsTokenVersionSizeInBytes /* Skip the version */, txnGuid, 0, txnGuid.Length); + Buffer.BlockCopy(_connection.PromotedDTCToken, _globalTransactionsTokenVersionSizeInBytes /* Skip the version */, txnGuid, 0, txnGuid.Length); return new Guid(txnGuid); } } diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlSequentialTextReader.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlSequentialTextReader.cs index b1b4a4fed2..504fd99934 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlSequentialTextReader.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlSequentialTextReader.cs @@ -372,7 +372,7 @@ private byte[] PrepareByteBuffer(int numberOfChars, out int byteBufferUsed) { // Otherwise, copy over the leftover buffer byteBuffer = new byte[byteBufferSize]; - Array.Copy(_leftOverBytes, byteBuffer, _leftOverBytes.Length); + Buffer.BlockCopy(_leftOverBytes, 0, byteBuffer, 0,_leftOverBytes.Length); byteBufferUsed = _leftOverBytes.Length; } } @@ -411,7 +411,7 @@ private int DecodeBytesToChars(byte[] inBuffer, int inBufferCount, char[] outBuf if ((!completed) && (bytesUsed < inBufferCount)) { _leftOverBytes = new byte[inBufferCount - bytesUsed]; - Array.Copy(inBuffer, bytesUsed, _leftOverBytes, 0, _leftOverBytes.Length); + Buffer.BlockCopy(inBuffer, bytesUsed, _leftOverBytes, 0, _leftOverBytes.Length); } else { diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlStream.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlStream.cs index 4e0f723361..9896fee14c 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlStream.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlStream.cs @@ -452,7 +452,7 @@ override public int Read(byte[] buffer, int offset, int count) cb = _cachedBytes[_currentArrayIndex].Length - _currentPosition; if (cb > count) cb = count; - Array.Copy(_cachedBytes[_currentArrayIndex], _currentPosition, buffer, offset, cb); + Buffer.BlockCopy(_cachedBytes[_currentArrayIndex], _currentPosition, buffer, offset, cb); _currentPosition += cb; count -= (int)cb; diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Server/SqlMetaData.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Server/SqlMetaData.cs index e5bb5b0047..a8d372aa2e 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Server/SqlMetaData.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Server/SqlMetaData.cs @@ -1285,7 +1285,7 @@ public SqlBinary Adjust(SqlBinary value) { byte[] rgbValue = value.Value; byte[] rgbNewValue = new byte[MaxLength]; - Array.Copy(rgbValue, rgbNewValue, rgbValue.Length); + Buffer.BlockCopy(rgbValue, 0, rgbNewValue, 0, rgbValue.Length); Array.Clear(rgbNewValue, rgbValue.Length, rgbNewValue.Length - rgbValue.Length); return new SqlBinary(rgbNewValue); } @@ -1307,7 +1307,7 @@ public SqlBinary Adjust(SqlBinary value) { byte[] rgbValue = value.Value; byte[] rgbNewValue = new byte[MaxLength]; - Array.Copy(rgbValue, rgbNewValue, (int)MaxLength); + Buffer.BlockCopy(rgbValue,0, rgbNewValue,0, (int)MaxLength); value = new SqlBinary(rgbNewValue); } @@ -1399,7 +1399,7 @@ public SqlBytes Adjust(SqlBytes value) if (value.MaxLength < MaxLength) { byte[] rgbNew = new byte[MaxLength]; - Array.Copy(value.Buffer, rgbNew, (int)oldLength); + Buffer.BlockCopy(value.Buffer, 0,rgbNew,0, (int)oldLength); value = new SqlBytes(rgbNew); } @@ -1928,7 +1928,7 @@ public byte[] Adjust(byte[] value) if (value.Length < MaxLength) { byte[] rgbNewValue = new byte[MaxLength]; - Array.Copy(value, rgbNewValue, value.Length); + Buffer.BlockCopy(value, 0, rgbNewValue, 0, value.Length); Array.Clear(rgbNewValue, value.Length, (int)rgbNewValue.Length - value.Length); return rgbNewValue; } @@ -1949,7 +1949,7 @@ public byte[] Adjust(byte[] value) if (value.Length > MaxLength && Max != MaxLength) { byte[] rgbNewValue = new byte[MaxLength]; - Array.Copy(value, rgbNewValue, (int)MaxLength); + Buffer.BlockCopy(value, 0, rgbNewValue, 0, (int)MaxLength); value = rgbNewValue; } diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Server/ValueUtilsSmi.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Server/ValueUtilsSmi.cs index 553377e005..c2acf5544a 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Server/ValueUtilsSmi.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Server/ValueUtilsSmi.cs @@ -124,7 +124,7 @@ private static long GetBytesConversion(SmiEventSink_Default sink, ITypedGettersV length = CheckXetParameters(metaData.SqlDbType, metaData.MaxLength * sizeof(char), value.Length, fieldOffset, buffer.Length, bufferOffset, length); - Array.Copy(value.Value, checked((int)fieldOffset), buffer, bufferOffset, length); + Buffer.BlockCopy(value.Value, checked((int)fieldOffset), buffer, bufferOffset, length); return length; } diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/DataStreamTest/DataStreamTest.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/DataStreamTest/DataStreamTest.cs index 8026aa479c..dba70d5fcd 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/DataStreamTest/DataStreamTest.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/DataStreamTest/DataStreamTest.cs @@ -130,7 +130,7 @@ private static byte[] CreateBinaryTable(SqlConnection connection, string tableNa while (position < data.Length) { int copyCount = Math.Min(pattern.Length, data.Length - position); - Array.Copy(pattern, 0, data, position, copyCount); + Buffer.BlockCopy(pattern, 0, data, position, copyCount); position += copyCount; } diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ParameterTest/StreamInputParam.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ParameterTest/StreamInputParam.cs index 91676446d8..53e58c1542 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ParameterTest/StreamInputParam.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ParameterTest/StreamInputParam.cs @@ -93,7 +93,7 @@ private int ReadInternal(byte[] buffer, int offset, int count) } if (_errorPos >= _pos && _errorPos < _pos + nRead) throw new CustomStreamException(); - Array.Copy(_data, _pos, buffer, offset, nRead); + Buffer.BlockCopy(_data, _pos, buffer, offset, nRead); _pos += nRead; return nRead; } diff --git a/src/Microsoft.Data.SqlClient/tests/tools/TDS/TDS/TDSStream.cs b/src/Microsoft.Data.SqlClient/tests/tools/TDS/TDS/TDSStream.cs index 90a295bbc1..94abbf5818 100644 --- a/src/Microsoft.Data.SqlClient/tests/tools/TDS/TDS/TDSStream.cs +++ b/src/Microsoft.Data.SqlClient/tests/tools/TDS/TDS/TDSStream.cs @@ -349,7 +349,7 @@ public override void Write(byte[] buffer, int offset, int count) if (packetDataToWrite > 0) { // Append new data to the end of the packet data - Array.Copy(buffer, bufferWrittenPosition + offset, _outgoingPacket, OutgoingPacketHeader.Length, packetDataToWrite); + Buffer.BlockCopy(buffer, bufferWrittenPosition + offset, _outgoingPacket, OutgoingPacketHeader.Length, packetDataToWrite); // Register that we've written new data bufferWrittenPosition += packetDataToWrite;