Removed ErrEndOfBuffer checks which are not required.

This commit is contained in:
scruzin 2019-01-13 10:10:43 +10:30
parent 9ff10dbbac
commit f8b8d06b2e
1 changed files with 2 additions and 37 deletions

View File

@ -86,11 +86,7 @@ type Property struct {
// AMF errors.
var (
ErrShortBuffer = errors.New("amf: short buffer")
ErrEndOfBuffer = errors.New("amf: end of buffer")
ErrInvalidType = errors.New("amf: invalid type")
ErrUnimplemented = errors.New("amf: unimplemented feature")
ErrDecodingName = errors.New("amf: name decoding error")
ErrDecodingString = errors.New("amf: string decoding error")
ErrUnexpectedEnd = errors.New("amf: unexpected end")
ErrPropertyNotFound = errors.New("amf: property not found")
)
@ -145,9 +141,6 @@ func EncodeInt24(buf []byte, val int32) ([]byte, error) {
buf[0] = byte(val >> 16)
buf[1] = byte(val >> 8)
buf[2] = byte(val)
if len(buf) == 3 {
return nil, ErrEndOfBuffer
}
return buf[3:], nil
}
@ -157,9 +150,6 @@ func EncodeInt32(buf []byte, val int32) ([]byte, error) {
return nil, ErrShortBuffer
}
binary.BigEndian.PutUint32(buf, uint32(val))
if len(buf) == 4 {
return nil, ErrEndOfBuffer
}
return buf[4:], nil
}
@ -180,9 +170,6 @@ func EncodeString(buf []byte, val string) ([]byte, error) {
binary.BigEndian.PutUint16(buf[:2], uint16(len(val)))
buf = buf[2:]
copy(buf, val)
if len(buf) == len(val) {
return nil, ErrEndOfBuffer
}
return buf[len(val):], nil
}
@ -191,9 +178,6 @@ func EncodeString(buf []byte, val string) ([]byte, error) {
binary.BigEndian.PutUint32(buf[:4], uint32(len(val)))
buf = buf[4:]
copy(buf, val)
if len(buf) == len(val) {
return nil, ErrEndOfBuffer
}
return buf[len(val):], nil
}
@ -219,9 +203,6 @@ func EncodeBoolean(buf []byte, val bool) ([]byte, error) {
} else {
buf[1] = 0
}
if len(buf) == 2 {
return nil, ErrEndOfBuffer
}
return buf[2:], nil
}
@ -234,9 +215,6 @@ func EncodeNamedString(buf []byte, key, val string) ([]byte, error) {
binary.BigEndian.PutUint16(buf[:2], uint16(len(key)))
buf = buf[2:]
copy(buf, key)
if len(key) == len(buf) {
return nil, ErrEndOfBuffer
}
return EncodeString(buf[len(key):], val)
}
@ -248,9 +226,6 @@ func EncodeNamedNumber(buf []byte, key string, val float64) ([]byte, error) {
binary.BigEndian.PutUint16(buf[:2], uint16(len(key)))
buf = buf[2:]
copy(buf, key)
if len(key) == len(buf) {
return nil, ErrEndOfBuffer
}
return EncodeNumber(buf[len(key):], val)
}
@ -262,9 +237,6 @@ func EncodeNamedBoolean(buf []byte, key string, val bool) ([]byte, error) {
binary.BigEndian.PutUint16(buf[:2], uint16(len(key)))
buf = buf[2:]
copy(buf, key)
if len(key) == len(buf) {
return nil, ErrEndOfBuffer
}
return EncodeBoolean(buf[len(key):], val)
}
@ -309,9 +281,6 @@ func EncodeProperty(prop *Property, buf []byte) ([]byte, error) {
// DecodeProperty decodes a property, returning the number of bytes consumed from the supplied buffer.
func DecodeProperty(prop *Property, buf []byte, decodeName bool) (int, error) {
sz := len(buf)
if len(buf) == 0 {
return 0, ErrEndOfBuffer
}
if decodeName {
if len(buf) < 4 {
@ -319,7 +288,7 @@ func DecodeProperty(prop *Property, buf []byte, decodeName bool) (int, error) {
}
n := DecodeInt16(buf[:2])
if int(n) > len(buf)-2 {
return 0, ErrDecodingName
return 0, ErrShortBuffer
}
prop.Name = DecodeString(buf)
@ -328,10 +297,6 @@ func DecodeProperty(prop *Property, buf []byte, decodeName bool) (int, error) {
prop.Name = ""
}
if len(buf) == 0 {
return 0, ErrEndOfBuffer
}
prop.Type = uint8(buf[0])
buf = buf[1:]
@ -380,7 +345,7 @@ func DecodeProperty(prop *Property, buf []byte, decodeName bool) (int, error) {
return 0, ErrUnexpectedEnd
default:
return 0, ErrUnimplemented
return 0, ErrInvalidType
}
return sz - len(buf), nil