Skip to content

Commit

Permalink
TdsParserStateObject: Removed unnecessary casts.
Browse files Browse the repository at this point in the history
  • Loading branch information
panoskj committed Oct 5, 2022
1 parent d71028b commit 3e05aeb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,7 @@ internal bool TryReadPlpLength(bool returnPlpNullIfNull, out ulong lengthLeft)
}
else
{
_longlenleft = (ulong)chunklen;
_longlenleft = chunklen;
}
}

Expand Down Expand Up @@ -992,7 +992,7 @@ internal bool TryReadPlpBytes(ref byte[] buff, int offset, int len, out int tota
if ((ulong)(buff?.Length ?? 0) != _longlen)
{
// if the buffer is null or the wrong length create one to use
buff = new byte[(int)Math.Min((int)_longlen, len)];
buff = new byte[(Math.Min((int)_longlen, len))];
}
}

Expand Down Expand Up @@ -1086,12 +1086,12 @@ internal bool TrySkipLongBytes(long num)

while (num > 0)
{
int cbSkip = (int)Math.Min((long)int.MaxValue, num);
int cbSkip = (int)Math.Min(int.MaxValue, num);
if (!TryReadByteArray(Span<byte>.Empty, cbSkip))
{
return false;
}
num -= (long)cbSkip;
num -= cbSkip;
}

return true;
Expand Down Expand Up @@ -1367,7 +1367,7 @@ private bool OnTimeoutCore(int expectedState, int targetState, bool asyncClose =
{
if (!_attentionSent)
{
AddError(new SqlError(TdsEnums.TIMEOUT_EXPIRED, (byte)0x00, TdsEnums.MIN_ERROR_CLASS, _parser.Server, _parser.Connection.TimeoutErrorInternal.GetErrorMessage(), "", 0, TdsEnums.SNI_WAIT_TIMEOUT));
AddError(new SqlError(TdsEnums.TIMEOUT_EXPIRED, 0x00, TdsEnums.MIN_ERROR_CLASS, _parser.Server, _parser.Connection.TimeoutErrorInternal.GetErrorMessage(), "", 0, TdsEnums.SNI_WAIT_TIMEOUT));

// Grab a reference to the _networkPacketTaskSource in case it becomes null while we are trying to use it
TaskCompletionSource<object> source = _networkPacketTaskSource;
Expand Down Expand Up @@ -1704,7 +1704,7 @@ private void ReadSniError(TdsParserStateObject stateObj, uint error)
{
stateObj.SetTimeoutStateStopped();
Debug.Assert(_parser.Connection != null, "SqlConnectionInternalTds handler can not be null at this point.");
AddError(new SqlError(TdsEnums.TIMEOUT_EXPIRED, (byte)0x00, TdsEnums.MIN_ERROR_CLASS, _parser.Server, _parser.Connection.TimeoutErrorInternal.GetErrorMessage(), "", 0, TdsEnums.SNI_WAIT_TIMEOUT));
AddError(new SqlError(TdsEnums.TIMEOUT_EXPIRED, 0x00, TdsEnums.MIN_ERROR_CLASS, _parser.Server, _parser.Connection.TimeoutErrorInternal.GetErrorMessage(), "", 0, TdsEnums.SNI_WAIT_TIMEOUT));

if (!stateObj._attentionSent)
{
Expand Down Expand Up @@ -2680,7 +2680,7 @@ private Task WriteSni(bool canAccumulate)
try
{
Debug.Assert(_parser.Connection != null, "SqlConnectionInternalTds handler can not be null at this point.");
AddError(new SqlError(TdsEnums.TIMEOUT_EXPIRED, (byte)0x00, TdsEnums.MIN_ERROR_CLASS, _parser.Server, _parser.Connection.TimeoutErrorInternal.GetErrorMessage(), "", 0, TdsEnums.SNI_WAIT_TIMEOUT));
AddError(new SqlError(TdsEnums.TIMEOUT_EXPIRED, 0x00, TdsEnums.MIN_ERROR_CLASS, _parser.Server, _parser.Connection.TimeoutErrorInternal.GetErrorMessage(), "", 0, TdsEnums.SNI_WAIT_TIMEOUT));
_bulkCopyWriteTimeout = true;
SendAttention();
_parser.ProcessPendingAck(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1044,7 +1044,7 @@ internal bool TryReadPlpLength(bool returnPlpNullIfNull, out ulong lengthLeft)
}
else
{
_longlenleft = (ulong)chunklen;
_longlenleft = chunklen;
}
}

Expand Down Expand Up @@ -1110,7 +1110,7 @@ internal bool TryReadPlpBytes(ref byte[] buff, int offst, int len, out int total
// If total length is known up front, allocate the whole buffer in one shot instead of realloc'ing and copying over each time
if (buff == null && _longlen != TdsEnums.SQL_PLP_UNKNOWNLEN)
{
buff = new byte[(int)Math.Min((int)_longlen, len)];
buff = new byte[(Math.Min((int)_longlen, len))];
}

if (_longlenleft == 0)
Expand Down Expand Up @@ -1190,12 +1190,12 @@ internal bool TrySkipLongBytes(long num)

while (num > 0)
{
int cbSkip = (int)Math.Min((long)int.MaxValue, num);
int cbSkip = (int)Math.Min(int.MaxValue, num);
if (!TryReadByteArray(Span<byte>.Empty, cbSkip))
{
return false;
}
num -= (long)cbSkip;
num -= cbSkip;
}

return true;
Expand Down Expand Up @@ -1465,7 +1465,7 @@ private bool OnTimeoutCore(int expectedState, int targetState, bool asyncClose =
{
if (!_attentionSent)
{
AddError(new SqlError(TdsEnums.TIMEOUT_EXPIRED, (byte)0x00, TdsEnums.MIN_ERROR_CLASS, _parser.Server, _parser.Connection.TimeoutErrorInternal.GetErrorMessage(), "", 0, TdsEnums.SNI_WAIT_TIMEOUT));
AddError(new SqlError(TdsEnums.TIMEOUT_EXPIRED, 0x00, TdsEnums.MIN_ERROR_CLASS, _parser.Server, _parser.Connection.TimeoutErrorInternal.GetErrorMessage(), "", 0, TdsEnums.SNI_WAIT_TIMEOUT));

// Grab a reference to the _networkPacketTaskSource in case it becomes null while we are trying to use it
TaskCompletionSource<object> source = _networkPacketTaskSource;
Expand Down Expand Up @@ -1826,7 +1826,7 @@ private void ReadSniError(TdsParserStateObject stateObj, uint error)
{
stateObj.SetTimeoutStateStopped();
Debug.Assert(_parser.Connection != null, "SqlConnectionInternalTds handler can not be null at this point.");
AddError(new SqlError(TdsEnums.TIMEOUT_EXPIRED, (byte)0x00, TdsEnums.MIN_ERROR_CLASS, _parser.Server, _parser.Connection.TimeoutErrorInternal.GetErrorMessage(), "", 0, TdsEnums.SNI_WAIT_TIMEOUT));
AddError(new SqlError(TdsEnums.TIMEOUT_EXPIRED, 0x00, TdsEnums.MIN_ERROR_CLASS, _parser.Server, _parser.Connection.TimeoutErrorInternal.GetErrorMessage(), "", 0, TdsEnums.SNI_WAIT_TIMEOUT));

if (!stateObj._attentionSent)
{
Expand Down Expand Up @@ -2746,7 +2746,7 @@ private Task WriteSni(bool canAccumulate)
try
{
Debug.Assert(_parser.Connection != null, "SqlConnectionInternalTds handler can not be null at this point.");
AddError(new SqlError(TdsEnums.TIMEOUT_EXPIRED, (byte)0x00, TdsEnums.MIN_ERROR_CLASS, _parser.Server, _parser.Connection.TimeoutErrorInternal.GetErrorMessage(), "", 0, TdsEnums.SNI_WAIT_TIMEOUT));
AddError(new SqlError(TdsEnums.TIMEOUT_EXPIRED, 0x00, TdsEnums.MIN_ERROR_CLASS, _parser.Server, _parser.Connection.TimeoutErrorInternal.GetErrorMessage(), "", 0, TdsEnums.SNI_WAIT_TIMEOUT));
_bulkCopyWriteTimeout = true;
SendAttention();
_parser.ProcessPendingAck(this);
Expand Down

0 comments on commit 3e05aeb

Please sign in to comment.