Skip to content

Commit 882045a

Browse files
authored
Align BitConverter/BinaryPrimitives usage netfx/netcore (#2963)
1 parent 16890fb commit 882045a

File tree

1 file changed

+10
-9
lines changed
  • src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient

1 file changed

+10
-9
lines changed

src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/TdsParser.cs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
using System;
66
using System.Buffers;
7+
using System.Buffers.Binary;
78
using System.Collections.Generic;
89
using System.Data;
910
using System.Data.SqlTypes;
@@ -4403,8 +4404,8 @@ private TdsOperationStatus TryProcessFedAuthInfo(TdsParserStateObject stateObj,
44034404
uint currentOptionOffset = checked(i * optionSize);
44044405

44054406
byte id = tokenData[currentOptionOffset];
4406-
uint dataLen = BitConverter.ToUInt32(tokenData, checked((int)(currentOptionOffset + 1)));
4407-
uint dataOffset = BitConverter.ToUInt32(tokenData, checked((int)(currentOptionOffset + 5)));
4407+
uint dataLen = BinaryPrimitives.ReadUInt32LittleEndian(tokenData.AsSpan(checked((int)(currentOptionOffset + 1))));
4408+
uint dataOffset = BinaryPrimitives.ReadUInt32LittleEndian(tokenData.AsSpan(checked((int)(currentOptionOffset + 5))));
44084409
if (SqlClientEventSource.Log.IsAdvancedTraceOn())
44094410
{
44104411
SqlClientEventSource.Log.AdvancedTraceEvent("<sc.TdsParser.TryProcessFedAuthInfo> FedAuthInfoOpt: ID={0}, DataLen={1}, Offset={2}", id, dataLen.ToString(CultureInfo.InvariantCulture), dataOffset.ToString(CultureInfo.InvariantCulture));
@@ -6830,7 +6831,7 @@ internal bool DeserializeUnencryptedValue(SqlBuffer value, byte[] unencryptedByt
68306831
return false;
68316832
}
68326833

6833-
longValue = BitConverter.ToInt64(unencryptedBytes, 0);
6834+
longValue = BinaryPrimitives.ReadInt64LittleEndian(unencryptedBytes);
68346835

68356836
if (tdsType == TdsEnums.SQLBIT ||
68366837
tdsType == TdsEnums.SQLBITN)
@@ -6868,7 +6869,7 @@ internal bool DeserializeUnencryptedValue(SqlBuffer value, byte[] unencryptedByt
68686869
return false;
68696870
}
68706871

6871-
singleValue = BitConverter.ToSingle(unencryptedBytes, 0);
6872+
singleValue = BitConverterCompatible.Int32BitsToSingle(BinaryPrimitives.ReadInt32LittleEndian(unencryptedBytes));
68726873
value.Single = singleValue;
68736874
break;
68746875

@@ -6879,7 +6880,7 @@ internal bool DeserializeUnencryptedValue(SqlBuffer value, byte[] unencryptedByt
68796880
return false;
68806881
}
68816882

6882-
doubleValue = BitConverter.ToDouble(unencryptedBytes, 0);
6883+
doubleValue = BitConverter.Int64BitsToDouble(BinaryPrimitives.ReadInt64LittleEndian(unencryptedBytes));
68836884
value.Double = doubleValue;
68846885
break;
68856886

@@ -6896,8 +6897,8 @@ internal bool DeserializeUnencryptedValue(SqlBuffer value, byte[] unencryptedByt
68966897
return false;
68976898
}
68986899

6899-
mid = BitConverter.ToInt32(unencryptedBytes, 0);
6900-
lo = BitConverter.ToUInt32(unencryptedBytes, 4);
6900+
mid = BinaryPrimitives.ReadInt32LittleEndian(unencryptedBytes);
6901+
lo = BinaryPrimitives.ReadUInt32LittleEndian(unencryptedBytes.AsSpan(4));
69016902

69026903
long l = (((long)mid) << 0x20) + ((long)lo);
69036904
value.SetToMoney(l);
@@ -6934,8 +6935,8 @@ internal bool DeserializeUnencryptedValue(SqlBuffer value, byte[] unencryptedByt
69346935
return false;
69356936
}
69366937

6937-
daypart = BitConverter.ToInt32(unencryptedBytes, 0);
6938-
timepart = BitConverter.ToUInt32(unencryptedBytes, 4);
6938+
daypart = BinaryPrimitives.ReadInt32LittleEndian(unencryptedBytes);
6939+
timepart = BinaryPrimitives.ReadUInt32LittleEndian(unencryptedBytes.AsSpan(4));
69396940
value.SetToDateTime(daypart, (int)timepart);
69406941
break;
69416942

0 commit comments

Comments
 (0)