Skip to content

Commit 359c4ba

Browse files
authored
make array rental return after TryReadPlpUnicodeChars unconditional (#2121)
1 parent 80905bd commit 359c4ba

File tree

1 file changed

+17
-10
lines changed
  • src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient

1 file changed

+17
-10
lines changed

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

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5683,18 +5683,20 @@ private bool TryReadSqlStringValue(SqlBuffer value, byte type, int length, Encod
56835683
{
56845684
char[] cc = null;
56855685
bool buffIsRented = false;
5686-
if (!TryReadPlpUnicodeChars(ref cc, 0, length >> 1, stateObj, out length, supportRentedBuff: true, rentedBuff: ref buffIsRented))
5687-
{
5688-
return false;
5689-
}
5690-
if (length > 0)
5691-
{
5692-
s = new string(cc, 0, length);
5693-
}
5694-
else
5686+
bool result = TryReadPlpUnicodeChars(ref cc, 0, length >> 1, stateObj, out length, supportRentedBuff: true, rentedBuff: ref buffIsRented);
5687+
5688+
if (result)
56955689
{
5696-
s = "";
5690+
if (length > 0)
5691+
{
5692+
s = new string(cc, 0, length);
5693+
}
5694+
else
5695+
{
5696+
s = "";
5697+
}
56975698
}
5699+
56985700
if (buffIsRented)
56995701
{
57005702
// do not use clearArray:true on the rented array because it can be massively larger
@@ -5705,6 +5707,11 @@ private bool TryReadSqlStringValue(SqlBuffer value, byte type, int length, Encod
57055707
ArrayPool<char>.Shared.Return(cc, clearArray: false);
57065708
cc = null;
57075709
}
5710+
5711+
if (!result)
5712+
{
5713+
return false;
5714+
}
57085715
}
57095716
else
57105717
{

0 commit comments

Comments
 (0)