Skip to content

Commit 2809526

Browse files
committed
Fix build on 32bit systems
Overflows on 32bit systems so you get a compile error.
1 parent 8e88f7e commit 2809526

4 files changed

Lines changed: 17 additions & 5 deletions

File tree

‎buf.go‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"encoding/binary"
66
"errors"
77
"fmt"
8-
"math"
98

109
"github.com/lib/pq/internal/proto"
1110
"github.com/lib/pq/oid"
@@ -83,7 +82,7 @@ func (b *writeBuf) bytes(v []byte) {
8382

8483
func (b *writeBuf) wrap() []byte {
8584
p := b.buf[b.pos:]
86-
if len(p) > math.MaxUint32 {
85+
if len(p) > proto.MaxUint32 {
8786
panic(fmt.Errorf("pq: message too large (%d > math.MaxUint32)", len(p)))
8887
}
8988
binary.BigEndian.PutUint32(p, uint32(len(p)))
@@ -92,7 +91,7 @@ func (b *writeBuf) wrap() []byte {
9291

9392
func (b *writeBuf) next(c proto.RequestCode) {
9493
p := b.buf[b.pos:]
95-
if len(p) > math.MaxUint32 {
94+
if len(p) > proto.MaxUint32 {
9695
panic(fmt.Errorf("pq: message too large (%d > math.MaxUint32)", len(p)))
9796
}
9897
binary.BigEndian.PutUint32(p, uint32(len(p)))

‎copy.go‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"encoding/binary"
88
"errors"
99
"fmt"
10-
"math"
1110
"sync"
1211

1312
"github.com/lib/pq/internal/proto"
@@ -159,7 +158,7 @@ awaitCopyInResponse:
159158
}
160159

161160
func (ci *copyin) flush(buf []byte) error {
162-
if len(buf)-1 > math.MaxUint32 {
161+
if len(buf)-1 > proto.MaxUint32 {
163162
return errors.New("pq: too many columns")
164163
}
165164
// set message length (without message identifier)

‎internal/proto/sz_32.go‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//go:build 386 || arm || mips || mipsle
2+
3+
package proto
4+
5+
import "math"
6+
7+
const MaxUint32 = math.MaxInt

‎internal/proto/sz_64.go‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//go:build !386 && !arm && !mips && !mipsle
2+
3+
package proto
4+
5+
import "math"
6+
7+
const MaxUint32 = math.MaxUint32

0 commit comments

Comments
 (0)