Skip to content

Commit

Permalink
Use math.MaxInt32
Browse files Browse the repository at this point in the history
  • Loading branch information
dajohi committed Aug 27, 2015
1 parent 7cc554c commit a829af9
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions xdr2/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ import (
"time"
)

const maxInt32 = int(^uint32(0) >> 1)

var errMaxSlice = "data exceeds max slice limit"
var errIODecode = "%s while decoding %d bytes"
var (
errMaxSlice = "data exceeds max slice limit"
errIODecode = "%s while decoding %d bytes"
)

/*
Unmarshal parses XDR-encoded data into the value pointed to by v reading from
Expand Down Expand Up @@ -306,7 +306,7 @@ func (d *Decoder) DecodeFixedOpaque(size int32) ([]byte, int, error) {

pad := (4 - (size % 4)) % 4
paddedSize := size + pad
if uint(paddedSize) > uint(maxInt32) {
if uint(paddedSize) > uint(math.MaxInt32) {
err := unmarshalError("DecodeFixedOpaque", ErrOverflow,
errMaxSlice, paddedSize, nil)
return nil, 0, err
Expand Down Expand Up @@ -338,7 +338,7 @@ func (d *Decoder) DecodeOpaque() ([]byte, int, error) {
if err != nil {
return nil, n, err
}
if uint(dataLen) > uint(maxInt32) {
if uint(dataLen) > uint(math.MaxInt32) {
err := unmarshalError("DecodeOpaque", ErrOverflow, errMaxSlice,
dataLen, nil)
return nil, n, err
Expand Down Expand Up @@ -371,7 +371,7 @@ func (d *Decoder) DecodeString() (string, int, error) {
if err != nil {
return "", n, err
}
if uint(dataLen) > uint(maxInt32) {
if uint(dataLen) > uint(math.MaxInt32) {
err = unmarshalError("DecodeString", ErrOverflow, errMaxSlice,
dataLen, nil)
return "", n, err
Expand Down Expand Up @@ -441,7 +441,7 @@ func (d *Decoder) decodeArray(v reflect.Value, ignoreOpaque bool) (int, error) {
if err != nil {
return n, err
}
if uint(dataLen) > uint(maxInt32) {
if uint(dataLen) > uint(math.MaxInt32) {
err := unmarshalError("decodeArray", ErrOverflow, errMaxSlice,
dataLen, nil)
return n, err
Expand Down

0 comments on commit a829af9

Please sign in to comment.