2
0

Fix scanning negative ints into Int64Scanner

This commit is contained in:
Jack Christensen
2022-02-08 14:13:06 -06:00
parent 1334d45d71
commit 0306ce3a19
4 changed files with 8 additions and 4 deletions
+3 -3
View File
@@ -552,7 +552,7 @@ func (scanPlanBinaryInt2ToInt64Scanner) Scan(src []byte, dst interface{}) error
return fmt.Errorf("invalid length for int2: %v", len(src))
}
n := int64(binary.BigEndian.Uint16(src))
n := int64(int16(binary.BigEndian.Uint16(src)))
return s.ScanInt64(Int8{Int: n, Valid: true})
}
@@ -1100,7 +1100,7 @@ func (scanPlanBinaryInt4ToInt64Scanner) Scan(src []byte, dst interface{}) error
return fmt.Errorf("invalid length for int4: %v", len(src))
}
n := int64(binary.BigEndian.Uint32(src))
n := int64(int32(binary.BigEndian.Uint32(src)))
return s.ScanInt64(Int8{Int: n, Valid: true})
}
@@ -1670,7 +1670,7 @@ func (scanPlanBinaryInt8ToInt64Scanner) Scan(src []byte, dst interface{}) error
return fmt.Errorf("invalid length for int8: %v", len(src))
}
n := int64(binary.BigEndian.Uint64(src))
n := int64(int64(binary.BigEndian.Uint64(src)))
return s.ScanInt64(Int8{Int: n, Valid: true})
}
+1 -1
View File
@@ -439,7 +439,7 @@ func (scanPlanBinaryInt<%= pg_byte_size %>ToInt64Scanner) Scan(src []byte, dst i
}
n := int64(binary.BigEndian.Uint<%= pg_bit_size %>(src))
n := int64(int<%= pg_bit_size %>(binary.BigEndian.Uint<%= pg_bit_size %>(src)))
return s.ScanInt64(Int8{Int: n, Valid: true})
}
+3
View File
@@ -22,6 +22,7 @@ func TestInt2Codec(t *testing.T) {
{int(1), new(int16), isExpectedEq(int16(1))},
{uint(1), new(int16), isExpectedEq(int16(1))},
{pgtype.Int2{Int: 1, Valid: true}, new(int16), isExpectedEq(int16(1))},
{int32(-1), new(pgtype.Int2), isExpectedEq(pgtype.Int2{Int: -1, Valid: true})},
{1, new(int8), isExpectedEq(int8(1))},
{1, new(int16), isExpectedEq(int16(1))},
{1, new(int32), isExpectedEq(int32(1))},
@@ -102,6 +103,7 @@ func TestInt4Codec(t *testing.T) {
{int(1), new(int32), isExpectedEq(int32(1))},
{uint(1), new(int32), isExpectedEq(int32(1))},
{pgtype.Int4{Int: 1, Valid: true}, new(int32), isExpectedEq(int32(1))},
{int32(-1), new(pgtype.Int4), isExpectedEq(pgtype.Int4{Int: -1, Valid: true})},
{1, new(int8), isExpectedEq(int8(1))},
{1, new(int16), isExpectedEq(int16(1))},
{1, new(int32), isExpectedEq(int32(1))},
@@ -182,6 +184,7 @@ func TestInt8Codec(t *testing.T) {
{int(1), new(int64), isExpectedEq(int64(1))},
{uint(1), new(int64), isExpectedEq(int64(1))},
{pgtype.Int8{Int: 1, Valid: true}, new(int64), isExpectedEq(int64(1))},
{int32(-1), new(pgtype.Int8), isExpectedEq(pgtype.Int8{Int: -1, Valid: true})},
{1, new(int8), isExpectedEq(int8(1))},
{1, new(int16), isExpectedEq(int16(1))},
{1, new(int32), isExpectedEq(int32(1))},
+1
View File
@@ -22,6 +22,7 @@ func TestInt<%= pg_byte_size %>Codec(t *testing.T) {
{int(1), new(int<%= pg_bit_size %>), isExpectedEq(int<%= pg_bit_size %>(1))},
{uint(1), new(int<%= pg_bit_size %>), isExpectedEq(int<%= pg_bit_size %>(1))},
{pgtype.Int<%= pg_byte_size %>{Int: 1, Valid: true}, new(int<%= pg_bit_size %>), isExpectedEq(int<%= pg_bit_size %>(1))},
{int32(-1), new(pgtype.Int<%= pg_byte_size %>), isExpectedEq(pgtype.Int<%= pg_byte_size %>{Int: -1, Valid: true})},
{1, new(int8), isExpectedEq(int8(1))},
{1, new(int16), isExpectedEq(int16(1))},
{1, new(int32), isExpectedEq(int32(1))},