mirror of https://github.com/jackc/pgx.git
Do not create empty slices in Bind.Decode
parent
dbcfa46d8e
commit
3080d0ee4d
|
@ -209,8 +209,6 @@ func PgxInitSteps() []Step {
|
|||
}),
|
||||
SendMessage(&pgproto3.ReadyForQuery{TxStatus: 'I'}),
|
||||
ExpectMessage(&pgproto3.Bind{
|
||||
ParameterFormatCodes: []int16{},
|
||||
Parameters: [][]byte{},
|
||||
ResultFormatCodes: []int16{1, 1},
|
||||
}),
|
||||
ExpectMessage(&pgproto3.Execute{}),
|
||||
|
|
|
@ -18,6 +18,8 @@ type Bind struct {
|
|||
func (*Bind) Frontend() {}
|
||||
|
||||
func (dst *Bind) Decode(src []byte) error {
|
||||
*dst = Bind{}
|
||||
|
||||
idx := bytes.IndexByte(src, 0)
|
||||
if idx < 0 {
|
||||
return &invalidMessageFormatErr{messageType: "Bind"}
|
||||
|
@ -38,6 +40,7 @@ func (dst *Bind) Decode(src []byte) error {
|
|||
parameterFormatCodeCount := int(binary.BigEndian.Uint16(src[rp:]))
|
||||
rp += 2
|
||||
|
||||
if parameterFormatCodeCount > 0 {
|
||||
dst.ParameterFormatCodes = make([]int16, parameterFormatCodeCount)
|
||||
|
||||
if len(src[rp:]) < len(dst.ParameterFormatCodes)*2 {
|
||||
|
@ -47,6 +50,7 @@ func (dst *Bind) Decode(src []byte) error {
|
|||
dst.ParameterFormatCodes[i] = int16(binary.BigEndian.Uint16(src[rp:]))
|
||||
rp += 2
|
||||
}
|
||||
}
|
||||
|
||||
if len(src[rp:]) < 2 {
|
||||
return &invalidMessageFormatErr{messageType: "Bind"}
|
||||
|
@ -54,6 +58,7 @@ func (dst *Bind) Decode(src []byte) error {
|
|||
parameterCount := int(binary.BigEndian.Uint16(src[rp:]))
|
||||
rp += 2
|
||||
|
||||
if parameterCount > 0 {
|
||||
dst.Parameters = make([][]byte, parameterCount)
|
||||
|
||||
for i := 0; i < parameterCount; i++ {
|
||||
|
@ -76,6 +81,7 @@ func (dst *Bind) Decode(src []byte) error {
|
|||
dst.Parameters[i] = src[rp : rp+msgSize]
|
||||
rp += msgSize
|
||||
}
|
||||
}
|
||||
|
||||
if len(src[rp:]) < 2 {
|
||||
return &invalidMessageFormatErr{messageType: "Bind"}
|
||||
|
|
Loading…
Reference in New Issue