Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
KirillKurdyukov committed Aug 8, 2024
1 parent 39cb035 commit ffb1d10
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 18 deletions.
20 changes: 7 additions & 13 deletions src/Ydb.Sdk/src/Ado/YdbDataReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,10 @@ public override long GetBytes(int ordinal, long dataOffset, byte[]? buffer, int
return 0;
}

var i = 0;
for (; i + dataOffset < bytes.Length && i < length; i++)
{
buffer[i + bufferOffset] = bytes[i + (int)dataOffset];
}
var copyCount = Math.Min(bytes.Length - dataOffset, length);
Array.Copy(bytes, (int)dataOffset, buffer, bufferOffset, copyCount);

return i;
return copyCount;
}

public override char GetChar(int ordinal)
Expand All @@ -92,7 +89,7 @@ public override char GetChar(int ordinal)

public override long GetChars(int ordinal, long dataOffset, char[]? buffer, int bufferOffset, int length)
{
var chars = GetString(ordinal);
var chars = GetString(ordinal).ToCharArray();

CheckOffsets(dataOffset, buffer, bufferOffset, length);

Expand All @@ -101,13 +98,10 @@ public override long GetChars(int ordinal, long dataOffset, char[]? buffer, int
return 0;
}

var i = 0;
for (; i + dataOffset < chars.Length && i < length; i++)
{
buffer[i + bufferOffset] = chars[i + (int)dataOffset];
}
var copyCount = Math.Min(chars.Length - dataOffset, length);
Array.Copy(chars, (int)dataOffset, buffer, bufferOffset, copyCount);

return i;
return copyCount;
}

private static void CheckOffsets<T>(long dataOffset, T[]? buffer, int bufferOffset, int length)
Expand Down
6 changes: 1 addition & 5 deletions src/Ydb.Sdk/tests/Ado/YdbCommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,6 @@ public void GetChars_WhenSelectText_MoveCharsToBuffer()
Assert.Equal($"dataOffset must be between 0 and {int.MaxValue}",
Assert.Throws<IndexOutOfRangeException>(
() => ydbDataReader.GetChars(0, long.MaxValue, null, 0, 6)).Message);
Assert.Equal(0, ydbDataReader.GetChars(0, int.MaxValue, bufferChars, 0, 6));
Assert.Equal(checkBuffer, bufferChars);

Assert.Equal("bufferOffset must be between 0 and 10", Assert.Throws<IndexOutOfRangeException>(
() => ydbDataReader.GetChars(0, 0, bufferChars, -1, 6)).Message);
Expand Down Expand Up @@ -237,8 +235,6 @@ public void GetBytes_WhenSelectBytes_MoveBytesToBuffer()
Assert.Equal($"dataOffset must be between 0 and {int.MaxValue}",
Assert.Throws<IndexOutOfRangeException>(
() => ydbDataReader.GetBytes(0, long.MaxValue, null, 0, 6)).Message);
Assert.Equal(0, ydbDataReader.GetBytes(0, int.MaxValue, bufferChars, 0, 6));
Assert.Equal(checkBuffer, bufferChars);

Assert.Equal("bufferOffset must be between 0 and 10", Assert.Throws<IndexOutOfRangeException>(
() => ydbDataReader.GetBytes(0, 0, bufferChars, -1, 6)).Message);
Expand All @@ -261,7 +257,7 @@ public void GetBytes_WhenSelectBytes_MoveBytesToBuffer()
bufferChars = new byte[10];
checkBuffer = new byte[10];

Assert.Equal(4, ydbDataReader.GetBytes(0, 3, bufferChars, 4, 6));
Assert.Equal(4, ydbDataReader.GetBytes(0, 3, bufferChars, 4, 5));
checkBuffer[4] = (byte)'c';
checkBuffer[5] = (byte)'a';
checkBuffer[6] = (byte)'b';
Expand Down

0 comments on commit ffb1d10

Please sign in to comment.