diff --git a/src/libraries/Common/src/System/Net/Logging/GlobalLog.cs b/src/libraries/Common/src/System/Net/Logging/GlobalLog.cs index 5b6f8eea7ad0a..1705317efaba9 100644 --- a/src/libraries/Common/src/System/Net/Logging/GlobalLog.cs +++ b/src/libraries/Common/src/System/Net/Logging/GlobalLog.cs @@ -248,7 +248,7 @@ public static void Dump(byte[] buffer, int offset, int length) } var bufferSegment = new byte[length]; - Array.Copy(buffer, offset, bufferSegment, 0, length); + Buffer.BlockCopy(buffer, offset, bufferSegment, 0, length); EventSourceLogging.Log.DebugDumpArray(bufferSegment); } diff --git a/src/libraries/Common/src/System/Security/Cryptography/RSAOpenSsl.cs b/src/libraries/Common/src/System/Security/Cryptography/RSAOpenSsl.cs index c3328fc89222e..13e9cd6599804 100644 --- a/src/libraries/Common/src/System/Security/Cryptography/RSAOpenSsl.cs +++ b/src/libraries/Common/src/System/Security/Cryptography/RSAOpenSsl.cs @@ -108,7 +108,7 @@ public override byte[] Decrypt(byte[] data, RSAEncryptionPadding padding) } byte[] plainBytes = new byte[returnValue]; - Array.Copy(buf, 0, plainBytes, 0, returnValue); + Buffer.BlockCopy(buf, 0, plainBytes, 0, returnValue); return plainBytes; } diff --git a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/Symbols/SymbolManagerBase.cs b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/Symbols/SymbolManagerBase.cs index 2e219e7d13a32..ce52fec4501d3 100644 --- a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/Symbols/SymbolManagerBase.cs +++ b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/Symbols/SymbolManagerBase.cs @@ -400,7 +400,7 @@ public TypeArray AllocParams(params CType[] types) public TypeArray ConcatParams(CType[] prgtype1, CType[] prgtype2) { CType[] combined = new CType[prgtype1.Length + prgtype2.Length]; - Array.Copy(prgtype1, combined, prgtype1.Length); + Array.Copy(prgtype1, 0, combined, 0, prgtype1.Length); Array.Copy(prgtype2, 0, combined, prgtype1.Length, prgtype2.Length); return AllocParams(combined); } diff --git a/src/libraries/System.ComponentModel.Annotations/src/System/ComponentModel/DataAnnotations/UIHintAttribute.cs b/src/libraries/System.ComponentModel.Annotations/src/System/ComponentModel/DataAnnotations/UIHintAttribute.cs index 665c941578b66..9f1077f079322 100644 --- a/src/libraries/System.ComponentModel.Annotations/src/System/ComponentModel/DataAnnotations/UIHintAttribute.cs +++ b/src/libraries/System.ComponentModel.Annotations/src/System/ComponentModel/DataAnnotations/UIHintAttribute.cs @@ -100,7 +100,7 @@ public UIHintImplementation(string uiHint, string presentationLayer, params obje if (controlParameters != null) { _inputControlParameters = new object[controlParameters.Length]; - Array.Copy(controlParameters, _inputControlParameters, controlParameters.Length); + Array.Copy(controlParameters, 0, _inputControlParameters, 0, controlParameters.Length); } } diff --git a/src/libraries/System.Data.SqlClient/src/System/Data/Common/DataRecordInternal.cs b/src/libraries/System.Data.SqlClient/src/System/Data/Common/DataRecordInternal.cs index 1ce2fc657d0cf..22876ea687bdb 100644 --- a/src/libraries/System.Data.SqlClient/src/System/Data/Common/DataRecordInternal.cs +++ b/src/libraries/System.Data.SqlClient/src/System/Data/Common/DataRecordInternal.cs @@ -143,7 +143,7 @@ public override long GetBytes(int i, long dataIndex, byte[] buffer, int bufferIn } // until arrays are 64 bit, we have to do these casts - Array.Copy(data, ndataIndex, buffer, bufferIndex, (int)cbytes); + Buffer.BlockCopy(data, ndataIndex, buffer, bufferIndex, (int)cbytes); } catch (Exception e) { diff --git a/src/libraries/System.Data.SqlClient/src/System/Data/Sql/SqlMetaData.cs b/src/libraries/System.Data.SqlClient/src/System/Data/Sql/SqlMetaData.cs index 452757bd92499..bc01df37514bd 100644 --- a/src/libraries/System.Data.SqlClient/src/System/Data/Sql/SqlMetaData.cs +++ b/src/libraries/System.Data.SqlClient/src/System/Data/Sql/SqlMetaData.cs @@ -942,7 +942,7 @@ public SqlBinary Adjust(SqlBinary value) { byte[] rgbValue = value.Value; byte[] rgbNewValue = new byte[MaxLength]; - Array.Copy(rgbValue, 0, rgbNewValue, 0, rgbValue.Length); + Buffer.BlockCopy(rgbValue, 0, rgbNewValue, 0, rgbValue.Length); Array.Clear(rgbNewValue, rgbValue.Length, rgbNewValue.Length - rgbValue.Length); return new SqlBinary(rgbNewValue); } @@ -963,7 +963,7 @@ public SqlBinary Adjust(SqlBinary value) { byte[] rgbValue = value.Value; byte[] rgbNewValue = new byte[MaxLength]; - Array.Copy(rgbValue, 0, rgbNewValue, 0, (int)MaxLength); + Buffer.BlockCopy(rgbValue, 0, rgbNewValue, 0, (int)MaxLength); value = new SqlBinary(rgbNewValue); } @@ -1040,7 +1040,7 @@ public SqlBytes Adjust(SqlBytes value) if (value.MaxLength < MaxLength) { byte[] rgbNew = new byte[MaxLength]; - Array.Copy(value.Buffer, 0, rgbNew, 0, (int)oldLength); + Buffer.BlockCopy(value.Buffer, 0, rgbNew, 0, (int)oldLength); value = new SqlBytes(rgbNew); } @@ -1380,7 +1380,7 @@ public byte[] Adjust(byte[] value) if (value.Length < MaxLength) { byte[] rgbNewValue = new byte[MaxLength]; - Array.Copy(value, 0, rgbNewValue, 0, value.Length); + Buffer.BlockCopy(value, 0, rgbNewValue, 0, value.Length); Array.Clear(rgbNewValue, value.Length, (int)rgbNewValue.Length - value.Length); return rgbNewValue; } @@ -1400,7 +1400,7 @@ public byte[] Adjust(byte[] value) if (value.Length > MaxLength && Max != MaxLength) { byte[] rgbNewValue = new byte[MaxLength]; - Array.Copy(value, 0, rgbNewValue, 0, (int)MaxLength); + Buffer.BlockCopy(value, 0, rgbNewValue, 0, (int)MaxLength); value = rgbNewValue; } diff --git a/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/SNI/SNIPacket.cs b/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/SNI/SNIPacket.cs index d20ef82cc7b7b..f3a87a6f7273a 100644 --- a/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/SNI/SNIPacket.cs +++ b/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/SNI/SNIPacket.cs @@ -124,7 +124,7 @@ public SNIPacket Clone() { SNIPacket packet = new SNIPacket(null); packet._data = new byte[_length]; - Array.Copy(_data, 0, packet._data, 0, _length); + Buffer.BlockCopy(_data, 0, packet._data, 0, _length); packet._length = _length; return packet; diff --git a/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/SqlDataReader.cs b/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/SqlDataReader.cs index 8e8a84e051d6e..834b07063d405 100644 --- a/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/SqlDataReader.cs +++ b/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/SqlDataReader.cs @@ -1374,7 +1374,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/libraries/System.Data.SqlClient/src/System/Data/SqlClient/SqlSequentialTextReader.cs b/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/SqlSequentialTextReader.cs index 391f7185a20c9..13e505694a6f2 100644 --- a/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/SqlSequentialTextReader.cs +++ b/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/SqlSequentialTextReader.cs @@ -371,7 +371,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; } } @@ -410,7 +410,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/libraries/System.Data.SqlClient/src/System/Data/SqlClient/SqlStream.cs b/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/SqlStream.cs index 527c7ed866e82..b42e54d42184a 100644 --- a/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/SqlStream.cs +++ b/src/libraries/System.Data.SqlClient/src/System/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/libraries/System.Data.SqlClient/src/System/Data/SqlTypes/SQLBytes.cs b/src/libraries/System.Data.SqlClient/src/System/Data/SqlTypes/SQLBytes.cs index e8fa48d33ed2e..b6609f206204b 100644 --- a/src/libraries/System.Data.SqlClient/src/System/Data/SqlTypes/SQLBytes.cs +++ b/src/libraries/System.Data.SqlClient/src/System/Data/SqlTypes/SQLBytes.cs @@ -194,7 +194,7 @@ public byte[] Value default: buffer = new byte[_lCurLen]; - Array.Copy(m_rgbBuf, buffer, (int)_lCurLen); + System.Buffer.BlockCopy(m_rgbBuf, 0, buffer, 0, (int)_lCurLen); break; } @@ -343,7 +343,7 @@ public long Read(long offset, byte[] buffer, int offsetInBuffer, int count) default: // ProjectK\Core doesn't support long-typed array indexers Debug.Assert(offset < int.MaxValue); - Array.Copy(m_rgbBuf, checked((int)offset), buffer, offsetInBuffer, count); + System.Buffer.BlockCopy(m_rgbBuf, checked((int)offset), buffer, offsetInBuffer, count); break; } } @@ -409,7 +409,7 @@ public void Write(long offset, byte[] buffer, int offsetInBuffer, int count) { // ProjectK\Core doesn't support long-typed array indexers Debug.Assert(offset < int.MaxValue); - Array.Copy(buffer, offsetInBuffer, m_rgbBuf, checked((int)offset), count); + System.Buffer.BlockCopy(buffer, offsetInBuffer, m_rgbBuf, checked((int)offset), count); // If the last position that has been written is after // the current data length, reset the length diff --git a/src/libraries/System.Data.SqlClient/src/System/Data/SqlTypes/SQLChars.cs b/src/libraries/System.Data.SqlClient/src/System/Data/SqlTypes/SQLChars.cs index 17a793bc7ec7b..3c0272566aa22 100644 --- a/src/libraries/System.Data.SqlClient/src/System/Data/SqlTypes/SQLChars.cs +++ b/src/libraries/System.Data.SqlClient/src/System/Data/SqlTypes/SQLChars.cs @@ -186,7 +186,7 @@ public char[] Value default: buffer = new char[_lCurLen]; - Array.Copy(m_rgchBuf, buffer, (int)_lCurLen); + Array.Copy(m_rgchBuf, 0, buffer, 0, (int)_lCurLen); break; } diff --git a/src/libraries/System.Diagnostics.Tracing/src/System/Diagnostics/Tracing/EventCounter.cs b/src/libraries/System.Diagnostics.Tracing/src/System/Diagnostics/Tracing/EventCounter.cs index e38c2ce640758..245b6546d5ad8 100644 --- a/src/libraries/System.Diagnostics.Tracing/src/System/Diagnostics/Tracing/EventCounter.cs +++ b/src/libraries/System.Diagnostics.Tracing/src/System/Diagnostics/Tracing/EventCounter.cs @@ -285,7 +285,7 @@ private static void EnsureEventSourceIndexAvailable(int eventSourceIndex) else if (eventSourceIndex >= EventCounterGroup.s_eventCounterGroups.Length) { EventCounterGroup[] newEventCounterGroups = new EventCounterGroup[eventSourceIndex + 1]; - Array.Copy(EventCounterGroup.s_eventCounterGroups, newEventCounterGroups, EventCounterGroup.s_eventCounterGroups.Length); + Array.Copy(EventCounterGroup.s_eventCounterGroups, 0, newEventCounterGroups, 0, EventCounterGroup.s_eventCounterGroups.Length); EventCounterGroup.s_eventCounterGroups = newEventCounterGroups; } } diff --git a/src/libraries/System.Diagnostics.Tracing/src/System/Diagnostics/Tracing/EventSource.cs b/src/libraries/System.Diagnostics.Tracing/src/System/Diagnostics/Tracing/EventSource.cs index be72b547603ce..8f35cfff68b95 100644 --- a/src/libraries/System.Diagnostics.Tracing/src/System/Diagnostics/Tracing/EventSource.cs +++ b/src/libraries/System.Diagnostics.Tracing/src/System/Diagnostics/Tracing/EventSource.cs @@ -3645,7 +3645,7 @@ private static void AddProviderEnumKind(ManifestBuilder manifest, FieldInfo stat if (eventData == null || eventData.Length <= eventAttribute.EventId) { EventMetadata[] newValues = new EventMetadata[Math.Max(eventData.Length + 16, eventAttribute.EventId + 1)]; - Array.Copy(eventData, newValues, eventData.Length); + Array.Copy(eventData, 0, newValues, 0, eventData.Length); eventData = newValues; } @@ -3684,7 +3684,7 @@ private static void TrimEventDescriptors(ref EventMetadata[] eventData) if (eventData.Length - idx > 2) // allow one wasted slot. { EventMetadata[] newValues = new EventMetadata[idx + 1]; - Array.Copy(eventData, newValues, newValues.Length); + Array.Copy(eventData, 0, newValues, 0, newValues.Length); eventData = newValues; } } diff --git a/src/libraries/System.IO/src/System/IO/BufferedStream.cs b/src/libraries/System.IO/src/System/IO/BufferedStream.cs index b3666cb86b650..e823ba7858dbe 100644 --- a/src/libraries/System.IO/src/System/IO/BufferedStream.cs +++ b/src/libraries/System.IO/src/System/IO/BufferedStream.cs @@ -134,7 +134,7 @@ private void EnsureShadowBufferAllocated() return; byte[] shadowBuffer = new byte[Math.Min(_bufferSize + _bufferSize, MaxShadowBufferSize)]; - Array.Copy(_buffer, 0, shadowBuffer, 0, _writePos); + Buffer.BlockCopy(_buffer, 0, shadowBuffer, 0, _writePos); _buffer = shadowBuffer; } @@ -416,7 +416,7 @@ private int ReadFromBuffer(byte[] array, int offset, int count) if (readbytes > count) readbytes = count; - Array.Copy(_buffer, _readPos, array, offset, readbytes); + Buffer.BlockCopy(_buffer, _readPos, array, offset, readbytes); _readPos += readbytes; return readbytes; @@ -683,7 +683,7 @@ private void WriteToBuffer(byte[] array, ref int offset, ref int count) return; EnsureBufferAllocated(); - Array.Copy(array, offset, _buffer, _writePos, bytesToWrite); + Buffer.BlockCopy(array, offset, _buffer, _writePos, bytesToWrite); _writePos += bytesToWrite; count -= bytesToWrite; @@ -825,7 +825,7 @@ public override void Write(byte[] array, int offset, int count) if (totalUserbytes <= (_bufferSize + _bufferSize) && totalUserbytes <= MaxShadowBufferSize) { EnsureShadowBufferAllocated(); - Array.Copy(array, offset, _buffer, _writePos, count); + Buffer.BlockCopy(array, offset, _buffer, _writePos, count); _stream.Write(_buffer, 0, totalUserbytes); _writePos = 0; return; @@ -977,7 +977,7 @@ public override Task WriteAsync(byte[] buffer, int offset, int count, Cancellati if (totalUserBytes <= (_bufferSize + _bufferSize) && totalUserBytes <= MaxShadowBufferSize) { EnsureShadowBufferAllocated(); - Array.Copy(array, offset, _buffer, _writePos, count); + Buffer.BlockCopy(array, offset, _buffer, _writePos, count); await _stream.WriteAsync(_buffer, 0, totalUserBytes, cancellationToken).ConfigureAwait(false); _writePos = 0; diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/Unix/CurlHandler.CurlResponseMessage.cs b/src/libraries/System.Net.Http/src/System/Net/Http/Unix/CurlHandler.CurlResponseMessage.cs index b7898edd8d0f7..bb66a856a930d 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/Unix/CurlHandler.CurlResponseMessage.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/Unix/CurlHandler.CurlResponseMessage.cs @@ -282,7 +282,7 @@ public override Task ReadAsync(byte[] buffer, int offset, int count, Cancel if (_remainingDataCount > 0) { int bytesToCopy = Math.Min(count, _remainingDataCount); - Array.Copy(_remainingData, _remainingDataOffset, buffer, offset, bytesToCopy); + Buffer.BlockCopy(_remainingData, _remainingDataOffset, buffer, offset, bytesToCopy); _remainingDataOffset += bytesToCopy; _remainingDataCount -= bytesToCopy; diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/SystemNetworkInterface.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/SystemNetworkInterface.cs index 25a55571affd7..634da253f955b 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/SystemNetworkInterface.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/SystemNetworkInterface.cs @@ -173,9 +173,9 @@ public override PhysicalAddress GetPhysicalAddress() { byte[] newAddr = new byte[_addressLength]; - // Array.Copy only supports int and long while addressLength is uint (see IpAdapterAddresses). + // Buffer.BlockCopy only supports int while addressLength is uint (see IpAdapterAddresses). // Will throw OverflowException if addressLength > Int32.MaxValue. - Array.Copy(_physicalAddress, 0, newAddr, 0, checked((int)_addressLength)); + Buffer.BlockCopy(_physicalAddress, 0, newAddr, 0, checked((int)_addressLength)); return new PhysicalAddress(newAddr); } diff --git a/src/libraries/System.Net.Ping/src/System/Net/NetworkInformation/Ping.Unix.cs b/src/libraries/System.Net.Ping/src/System/Net/NetworkInformation/Ping.Unix.cs index e1f456aeabfb8..4328ed588a940 100644 --- a/src/libraries/System.Net.Ping/src/System/Net/NetworkInformation/Ping.Unix.cs +++ b/src/libraries/System.Net.Ping/src/System/Net/NetworkInformation/Ping.Unix.cs @@ -113,7 +113,7 @@ private async Task SendIcmpEchoRequestOverRawSocket(IPAddress address int dataOffset = ipHeaderLength + IcmpHeaderLengthInBytes; // We want to return a buffer with the actual data we sent out, not including the header data. byte[] dataBuffer = new byte[bytesReceived - dataOffset]; - Array.Copy(receiveBuffer, dataOffset, dataBuffer, 0, dataBuffer.Length); + Buffer.BlockCopy(receiveBuffer, dataOffset, dataBuffer, 0, dataBuffer.Length); IPStatus status = isIpv4 ? IcmpV4MessageConstants.MapV4TypeToIPStatus(type, code) diff --git a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/Socket.cs b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/Socket.cs index a5e0ff0aac6c5..7fc98f3e5cc9f 100644 --- a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/Socket.cs +++ b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/Socket.cs @@ -4116,7 +4116,7 @@ internal Socket EndAccept(out byte[] buffer, IAsyncResult asyncResult) Socket socket = EndAccept(out innerBuffer, out bytesTransferred, asyncResult); buffer = new byte[bytesTransferred]; - Array.Copy(innerBuffer, 0, buffer, 0, bytesTransferred); + Buffer.BlockCopy(innerBuffer, 0, buffer, 0, bytesTransferred); return socket; } diff --git a/src/libraries/System.Private.DataContractSerialization/src/System/Xml/XmlBaseReader.cs b/src/libraries/System.Private.DataContractSerialization/src/System/Xml/XmlBaseReader.cs index c4832d42977bc..279d50764b59f 100644 --- a/src/libraries/System.Private.DataContractSerialization/src/System/Xml/XmlBaseReader.cs +++ b/src/libraries/System.Private.DataContractSerialization/src/System/Xml/XmlBaseReader.cs @@ -1370,9 +1370,9 @@ private int ReadBytes(Encoding encoding, int byteBlock, int charBlock, byte[] bu if (_trailByteCount > 0) { int actual = Math.Min(_trailByteCount, byteCount); - Array.Copy(_trailBytes, 0, buffer, offset, actual); + Buffer.BlockCopy(_trailBytes, 0, buffer, offset, actual); _trailByteCount -= actual; - Array.Copy(_trailBytes, actual, _trailBytes, 0, _trailByteCount); + Buffer.BlockCopy(_trailBytes, actual, _trailBytes, 0, _trailByteCount); return actual; } XmlNodeType nodeType = _node.NodeType; @@ -1440,9 +1440,9 @@ private int ReadBytes(Encoding encoding, int byteBlock, int charBlock, byte[] bu _trailBytes = new byte[3]; _trailByteCount = encoding.GetBytes(chars, 0, charCount, _trailBytes, 0); int actual = Math.Min(_trailByteCount, byteCount); - Array.Copy(_trailBytes, 0, buffer, offset, actual); + Buffer.BlockCopy(_trailBytes, 0, buffer, offset, actual); _trailByteCount -= actual; - Array.Copy(_trailBytes, actual, _trailBytes, 0, _trailByteCount); + Buffer.BlockCopy(_trailBytes, actual, _trailBytes, 0, _trailByteCount); return actual; } else diff --git a/src/libraries/System.Private.DataContractSerialization/src/System/Xml/XmlStreamNodeWriter.cs b/src/libraries/System.Private.DataContractSerialization/src/System/Xml/XmlStreamNodeWriter.cs index b321425ec6068..3357f0608886e 100644 --- a/src/libraries/System.Private.DataContractSerialization/src/System/Xml/XmlStreamNodeWriter.cs +++ b/src/libraries/System.Private.DataContractSerialization/src/System/Xml/XmlStreamNodeWriter.cs @@ -467,7 +467,7 @@ unsafe protected int UnsafeGetUTF8Chars(char* chars, int charCount, byte[] buffe string tmp = new string(charsStart, 0, (int)(chars - charsStart)); byte[] newBytes = _encoding != null ? _encoding.GetBytes(tmp) : s_UTF8Encoding.GetBytes(tmp); int toCopy = Math.Min(newBytes.Length, (int)(bytesMax - bytes)); - Array.Copy(newBytes, 0, buffer, (int)(bytes - _bytes) + offset, toCopy); + Buffer.BlockCopy(newBytes, 0, buffer, (int)(bytes - _bytes) + offset, toCopy); bytes += toCopy; diff --git a/src/libraries/System.Reflection.Metadata/src/System/Reflection/BlobBuilder.cs b/src/libraries/System.Reflection.Metadata/src/System/Reflection/BlobBuilder.cs index 50e9f259d1b0f..6cf9fbcdd8a08 100644 --- a/src/libraries/System.Reflection.Metadata/src/System/Reflection/BlobBuilder.cs +++ b/src/libraries/System.Reflection.Metadata/src/System/Reflection/BlobBuilder.cs @@ -305,7 +305,7 @@ public byte[] ToArray(int start, int byteCount) break; } - Array.Copy(chunk._buffer, Math.Max(start - chunkStartPosition, 0), result, resultOffset, bytesToCopy); + Buffer.BlockCopy(chunk._buffer, Math.Max(start - chunkStartPosition, 0), result, resultOffset, bytesToCopy); resultOffset += bytesToCopy; } diff --git a/src/libraries/System.Reflection.Metadata/src/System/Reflection/BlobWriter.cs b/src/libraries/System.Reflection.Metadata/src/System/Reflection/BlobWriter.cs index 911171ae6d3bd..6e27c9708a575 100644 --- a/src/libraries/System.Reflection.Metadata/src/System/Reflection/BlobWriter.cs +++ b/src/libraries/System.Reflection.Metadata/src/System/Reflection/BlobWriter.cs @@ -108,7 +108,7 @@ public byte[] ToArray(int start, int byteCount) BlobUtilities.ValidateRange(Length, start, byteCount); var result = new byte[byteCount]; - Array.Copy(_buffer, _start + start, result, 0, byteCount); + Buffer.BlockCopy(_buffer, _start + start, result, 0, byteCount); return result; } diff --git a/src/libraries/System.Runtime.WindowsRuntime/src/System/IO/BufferedStream.cs b/src/libraries/System.Runtime.WindowsRuntime/src/System/IO/BufferedStream.cs index 329c83f502de1..fee3b14fa2c7f 100644 --- a/src/libraries/System.Runtime.WindowsRuntime/src/System/IO/BufferedStream.cs +++ b/src/libraries/System.Runtime.WindowsRuntime/src/System/IO/BufferedStream.cs @@ -170,7 +170,7 @@ private void EnsureShadowBufferAllocated() return; Byte[] shadowBuffer = new Byte[Math.Min(_bufferSize + _bufferSize, MaxShadowBufferSize)]; - Array.Copy(_buffer, 0, shadowBuffer, 0, _writePos); + Buffer.BlockCopy(_buffer, 0, shadowBuffer, 0, _writePos); _buffer = shadowBuffer; } @@ -485,7 +485,7 @@ private Int32 ReadFromBuffer(Byte[] array, Int32 offset, Int32 count) if (readBytes > count) readBytes = count; - Array.Copy(_buffer, _readPos, array, offset, readBytes); + Buffer.BlockCopy(_buffer, _readPos, array, offset, readBytes); _readPos += readBytes; return readBytes; @@ -842,7 +842,7 @@ private void WriteToBuffer(Byte[] array, ref Int32 offset, ref Int32 count) return; EnsureBufferAllocated(); - Array.Copy(array, offset, _buffer, _writePos, bytesToWrite); + Buffer.BlockCopy(array, offset, _buffer, _writePos, bytesToWrite); _writePos += bytesToWrite; count -= bytesToWrite; @@ -986,7 +986,7 @@ public override void Write(Byte[] array, Int32 offset, Int32 count) if (totalUserBytes <= (_bufferSize + _bufferSize) && totalUserBytes <= MaxShadowBufferSize) { EnsureShadowBufferAllocated(); - Array.Copy(array, offset, _buffer, _writePos, count); + Buffer.BlockCopy(array, offset, _buffer, _writePos, count); _stream.Write(_buffer, 0, totalUserBytes); _writePos = 0; return; diff --git a/src/libraries/System.Runtime.WindowsRuntime/src/System/Runtime/InteropServices/WindowsRuntime/WindowsRuntimeBuffer.cs b/src/libraries/System.Runtime.WindowsRuntime/src/System/Runtime/InteropServices/WindowsRuntime/WindowsRuntimeBuffer.cs index 92bd0dbf3545f..49914438bcdad 100644 --- a/src/libraries/System.Runtime.WindowsRuntime/src/System/Runtime/InteropServices/WindowsRuntime/WindowsRuntimeBuffer.cs +++ b/src/libraries/System.Runtime.WindowsRuntime/src/System/Runtime/InteropServices/WindowsRuntime/WindowsRuntimeBuffer.cs @@ -65,7 +65,7 @@ public static IBuffer Create(Byte[] data, Int32 offset, Int32 length, Int32 capa Contract.EndContractBlock(); Byte[] underlyingData = new Byte[capacity]; - Array.Copy(data, offset, underlyingData, 0, length); + Buffer.BlockCopy(data, offset, underlyingData, 0, length); return new WindowsRuntimeBuffer(underlyingData, 0, length, capacity); } diff --git a/src/libraries/System.Runtime.WindowsRuntime/src/System/Runtime/InteropServices/WindowsRuntime/WindowsRuntimeBufferExtensions.cs b/src/libraries/System.Runtime.WindowsRuntime/src/System/Runtime/InteropServices/WindowsRuntime/WindowsRuntimeBufferExtensions.cs index 896d1f2503ad8..012fc266f4594 100644 --- a/src/libraries/System.Runtime.WindowsRuntime/src/System/Runtime/InteropServices/WindowsRuntime/WindowsRuntimeBufferExtensions.cs +++ b/src/libraries/System.Runtime.WindowsRuntime/src/System/Runtime/InteropServices/WindowsRuntime/WindowsRuntimeBufferExtensions.cs @@ -118,7 +118,7 @@ public static void CopyTo(this Byte[] source, Int32 sourceIndex, IBuffer destina Int32 destDataOffs; if (destination.TryGetUnderlyingData(out destDataArr, out destDataOffs)) { - Array.Copy(source, sourceIndex, destDataArr, (int)(destDataOffs + destinationIndex), count); + Buffer.BlockCopy(source, sourceIndex, destDataArr, (int)(destDataOffs + destinationIndex), count); return; } @@ -194,7 +194,7 @@ public static void CopyTo(this IBuffer source, UInt32 sourceIndex, Byte[] destin Int32 srcDataOffs; if (source.TryGetUnderlyingData(out srcDataArr, out srcDataOffs)) { - Array.Copy(srcDataArr, (int)(srcDataOffs + sourceIndex), destination, destinationIndex, count); + Buffer.BlockCopy(srcDataArr, (int)(srcDataOffs + sourceIndex), destination, destinationIndex, count); return; } @@ -245,7 +245,7 @@ public static void CopyTo(this IBuffer source, UInt32 sourceIndex, IBuffer desti Debug.Assert(sourceIndex <= Int32.MaxValue); Debug.Assert(destinationIndex <= Int32.MaxValue); - Array.Copy(srcDataArr, srcDataOffs + (Int32)sourceIndex, destDataArr, destDataOffs + (Int32)destinationIndex, (Int32)count); + Buffer.BlockCopy(srcDataArr, srcDataOffs + (Int32)sourceIndex, destDataArr, destDataOffs + (Int32)destinationIndex, (Int32)count); return; } diff --git a/src/libraries/System.Security.Cryptography.Algorithms/src/System/Security/Cryptography/Rfc2898DeriveBytes.cs b/src/libraries/System.Security.Cryptography.Algorithms/src/System/Security/Cryptography/Rfc2898DeriveBytes.cs index 961ab4a9bf32d..17bb4f20fde17 100644 --- a/src/libraries/System.Security.Cryptography.Algorithms/src/System/Security/Cryptography/Rfc2898DeriveBytes.cs +++ b/src/libraries/System.Security.Cryptography.Algorithms/src/System/Security/Cryptography/Rfc2898DeriveBytes.cs @@ -125,13 +125,13 @@ public override byte[] GetBytes(int cb) { if (cb >= size) { - Array.Copy(_buffer, _startIndex, password, 0, size); + Buffer.BlockCopy(_buffer, _startIndex, password, 0, size); _startIndex = _endIndex = 0; offset += size; } else { - Array.Copy(_buffer, _startIndex, password, 0, cb); + Buffer.BlockCopy(_buffer, _startIndex, password, 0, cb); _startIndex += cb; return password; } @@ -145,14 +145,14 @@ public override byte[] GetBytes(int cb) int remainder = cb - offset; if (remainder > BlockSize) { - Array.Copy(T_block, 0, password, offset, BlockSize); + Buffer.BlockCopy(T_block, 0, password, offset, BlockSize); offset += BlockSize; } else { - Array.Copy(T_block, 0, password, offset, remainder); + Buffer.BlockCopy(T_block, 0, password, offset, remainder); offset += remainder; - Array.Copy(T_block, remainder, _buffer, _startIndex, BlockSize - remainder); + Buffer.BlockCopy(T_block, remainder, _buffer, _startIndex, BlockSize - remainder); _endIndex += (BlockSize - remainder); return password; } diff --git a/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/CapiHelper.cs b/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/CapiHelper.cs index 2b5da882a41a4..17061b4df7d55 100644 --- a/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/CapiHelper.cs +++ b/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/CapiHelper.cs @@ -781,7 +781,7 @@ internal static void DecryptKey(SafeKeyHandle safeKeyHandle, byte[] encryptedDat throw new CryptographicException(SR.Format(SR.Argument_InvalidValue, "Encrypted data length is less than 0")); } byte[] dataTobeDecrypted = new byte[encryptedDataLength]; - Array.Copy(encryptedData, 0, dataTobeDecrypted, 0, encryptedDataLength); + Buffer.BlockCopy(encryptedData, 0, dataTobeDecrypted, 0, encryptedDataLength); Array.Reverse(dataTobeDecrypted); //ToDO: Check is this is really needed? To be confirmed with tests int dwFlags = fOAEP ? (int)CryptDecryptFlags.CRYPT_OAEP : 0; @@ -814,7 +814,7 @@ internal static void DecryptKey(SafeKeyHandle safeKeyHandle, byte[] encryptedDat decryptedData = new byte[decryptedDataLength]; - Array.Copy(dataTobeDecrypted, 0, decryptedData, 0, decryptedDataLength); + Buffer.BlockCopy(dataTobeDecrypted, 0, decryptedData, 0, decryptedDataLength); return; } @@ -857,7 +857,7 @@ internal static void EncryptKey(SafeKeyHandle safeKeyHandle, byte[] pbKey, int c // key should always be larger than the plaintext key, so use that to determine the buffer size. Debug.Assert(cbEncryptedKey >= cbKey); pbEncryptedKey = new byte[cbEncryptedKey]; - Array.Copy(pbKey, 0, pbEncryptedKey, 0, cbKey); + Buffer.BlockCopy(pbKey, 0, pbEncryptedKey, 0, cbKey); // Encrypt for real - the last parameter is the total size of the in/out buffer, while the second to last // parameter specifies the size of the plaintext to encrypt. diff --git a/src/libraries/System.Security.Cryptography.X509Certificates/src/Internal/Cryptography/FindPal.cs b/src/libraries/System.Security.Cryptography.X509Certificates/src/Internal/Cryptography/FindPal.cs index ebf9cfb663b33..436bf66ed9a54 100644 --- a/src/libraries/System.Security.Cryptography.X509Certificates/src/Internal/Cryptography/FindPal.cs +++ b/src/libraries/System.Security.Cryptography.X509Certificates/src/Internal/Cryptography/FindPal.cs @@ -262,7 +262,7 @@ internal static BigInteger PositiveBigIntegerFromByteArray(byte[] bytes) // Since the sign bit is set, put a new 0x00 on the end to move that bit from // the sign bit to a data bit. byte[] newBytes = new byte[bytes.Length + 1]; - Array.Copy(bytes, 0, newBytes, 0, bytes.Length); + Buffer.BlockCopy(bytes, 0, newBytes, 0, bytes.Length); return new BigInteger(newBytes); } diff --git a/src/libraries/System.Security.Cryptography.X509Certificates/src/Internal/Cryptography/Pal.Windows/X509Pal.CustomExtensions.cs b/src/libraries/System.Security.Cryptography.X509Certificates/src/Internal/Cryptography/Pal.Windows/X509Pal.CustomExtensions.cs index 975250782a527..3324b76b353a1 100644 --- a/src/libraries/System.Security.Cryptography.X509Certificates/src/Internal/Cryptography/Pal.Windows/X509Pal.CustomExtensions.cs +++ b/src/libraries/System.Security.Cryptography.X509Certificates/src/Internal/Cryptography/Pal.Windows/X509Pal.CustomExtensions.cs @@ -238,7 +238,7 @@ public byte[] ComputeCapiSha1OfPublicKey(PublicKey key) if (cb < buffer.Length) { byte[] newBuffer = new byte[cb]; - Array.Copy(buffer, 0, newBuffer, 0, cb); + Buffer.BlockCopy(buffer, 0, newBuffer, 0, cb); buffer = newBuffer; } return buffer; diff --git a/src/libraries/System.Security.Cryptography.X509Certificates/src/System/Security/Cryptography/X509Certificates/X509SubjectKeyIdentifierExtension.cs b/src/libraries/System.Security.Cryptography.X509Certificates/src/System/Security/Cryptography/X509Certificates/X509SubjectKeyIdentifierExtension.cs index fdaba29eb095d..925e0957d2eae 100644 --- a/src/libraries/System.Security.Cryptography.X509Certificates/src/System/Security/Cryptography/X509Certificates/X509SubjectKeyIdentifierExtension.cs +++ b/src/libraries/System.Security.Cryptography.X509Certificates/src/System/Security/Cryptography/X509Certificates/X509SubjectKeyIdentifierExtension.cs @@ -112,7 +112,7 @@ private static byte[] GenerateSubjectKeyIdentifierFromPublicKey(PublicKey key, X // SHA-1 hash of the value of the BIT STRING subjectPublicKey // (excluding the tag, length, and number of unused bit string bits) byte[] shortSha1 = new byte[8]; - Array.Copy(sha1, sha1.Length - 8, shortSha1, 0, shortSha1.Length); + Buffer.BlockCopy(sha1, sha1.Length - 8, shortSha1, 0, shortSha1.Length); shortSha1[0] &= 0x0f; shortSha1[0] |= 0x40; return shortSha1; diff --git a/src/libraries/System.Security.Principal.Windows/src/System/Security/Principal/WindowsIdentity.cs b/src/libraries/System.Security.Principal.Windows/src/System/Security/Principal/WindowsIdentity.cs index b839961f10914..5e2fb2bd32ffb 100644 --- a/src/libraries/System.Security.Principal.Windows/src/System/Security/Principal/WindowsIdentity.cs +++ b/src/libraries/System.Security.Principal.Windows/src/System/Security/Principal/WindowsIdentity.cs @@ -75,7 +75,7 @@ public WindowsIdentity(string sUserPrincipalName) if (!Interop.SecurityBase.AllocateLocallyUniqueId(out sourceContext.SourceIdentifier)) throw new SecurityException(new Win32Exception().Message); sourceContext.SourceName = new byte[TOKEN_SOURCE.TOKEN_SOURCE_LENGTH]; - Array.Copy(sourceName, 0, sourceContext.SourceName, 0, sourceName.Length); + Buffer.BlockCopy(sourceName, 0, sourceContext.SourceName, 0, sourceName.Length); // Desktop compat: Desktop never null-checks sUserPrincipalName. Actual behavior is that the null makes it down to Encoding.Unicode.GetBytes() which then throws // the ArgumentNullException (provided that the prior LSA calls didn't fail first.) To make this compat decision explicit, we'll null check ourselves diff --git a/src/libraries/System.Xml.ReaderWriter/src/System/Xml/BinHexDecoder.cs b/src/libraries/System.Xml.ReaderWriter/src/System/Xml/BinHexDecoder.cs index 82dbc236dcffb..f9e03773448ec 100644 --- a/src/libraries/System.Xml.ReaderWriter/src/System/Xml/BinHexDecoder.cs +++ b/src/libraries/System.Xml.ReaderWriter/src/System/Xml/BinHexDecoder.cs @@ -176,7 +176,7 @@ public static unsafe byte[] Decode(char[] chars, bool allowOddChars) if (bytesDecoded < bytes.Length) { byte[] tmp = new byte[bytesDecoded]; - Array.Copy(bytes, 0, tmp, 0, bytesDecoded); + Buffer.BlockCopy(bytes, 0, tmp, 0, bytesDecoded); bytes = tmp; }