Skip to content

Commit

Permalink
Fixed null writing bug
Browse files Browse the repository at this point in the history
When writing a null simple value that requires flushing
  • Loading branch information
roji committed Apr 16, 2018
1 parent 2451c2e commit 32c85a8
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/Npgsql/TypeHandling/NpgsqlSimpleTypeHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ protected NpgsqlSimpleTypeHandler()
/// <summary>
/// Reads a value of type <typeparamref name="TDefault"/> with the given length from the provided buffer,
/// with the assumption that it is entirely present in the provided memory buffer and no I/O will be
/// required.
/// required.
/// </summary>
/// <param name="buf">The buffer from which to read.</param>
/// <param name="len">The byte length of the value. The buffer might not contain the full length, requiring I/O to be performed.</param>
Expand Down Expand Up @@ -201,9 +201,6 @@ internal sealed override Task WriteWithLengthInternal<TAny>(TAny value, NpgsqlWr

async Task WriteWithLengthLong<TAny>([CanBeNull] TAny value, NpgsqlWriteBuffer buf, NpgsqlParameter parameter, bool async)
{
Debug.Assert(this is INpgsqlSimpleTypeHandler<TAny>);
var typedHandler = (INpgsqlSimpleTypeHandler<TAny>)this;

if (value == null || typeof(TAny) == typeof(DBNull))
{
if (buf.WriteSpaceLeft < 4)
Expand All @@ -212,6 +209,7 @@ async Task WriteWithLengthLong<TAny>([CanBeNull] TAny value, NpgsqlWriteBuffer b
return;
}

var typedHandler = (INpgsqlSimpleTypeHandler<TAny>)this;
var elementLen = typedHandler.ValidateAndGetLength(value, parameter);
if (buf.WriteSpaceLeft < 4 + elementLen)
await buf.Flush(async);
Expand Down

0 comments on commit 32c85a8

Please sign in to comment.