Skip to content
This repository has been archived by the owner on Jun 5, 2021. It is now read-only.

Commit

Permalink
lint: fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
ernado committed Aug 12, 2018
1 parent ba25813 commit 23c404c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -26,7 +26,7 @@ lint:
--vendor \
-e "_test.go.+(gocyclo|errcheck|dupl)" \
-e "attributes\.go.+credentials,.+,LOW.+\(gas\)" \
-e "parameter v always receives 8" \
-e "parameter v always receives 4" \
-e "function \(\*Client\).allocate\(\) is high .+\(gocyclo\)" \
--enable="lll" --line-length=100 \
--enable="gofmt" \
Expand Down
16 changes: 5 additions & 11 deletions chandata.go
Expand Up @@ -69,12 +69,6 @@ func (c *ChannelData) Encode() {
}
}

// STUN aligns attributes on 32-bit boundaries, attributes whose content
// is not a multiple of 4 bytes are padded with 1, 2, or 3 bytes of
// padding so that its value contains a multiple of 4 bytes. The
// padding bits are ignored, and may be any value.
//
// https://tools.ietf.org/html/rfc5389#section-15
const padding = 4

func nearestPaddedValueLength(l int) int {
Expand All @@ -87,15 +81,15 @@ func nearestPaddedValueLength(l int) int {

// WriteHeader writes channel number and length.
func (c *ChannelData) WriteHeader() {
if len(c.Raw) < 4 {
if len(c.Raw) < channelDataHeaderSize {
// Making WriteHeader call valid even when c.Raw
// is nil or len(c.Raw) is less than needed for header.
c.grow(4)
c.grow(channelDataHeaderSize)
}
// Early bounds check to guarantee safety of writes below.
_ = c.Raw[:channelDataHeaderSize]
bin.PutUint16(c.Raw[:2], uint16(c.Number))
bin.PutUint16(c.Raw[2:4],
bin.PutUint16(c.Raw[:channelDataNumberSize], uint16(c.Number))
bin.PutUint16(c.Raw[channelDataNumberSize:channelDataHeaderSize],
uint16(len(c.Data)),
)
}
Expand All @@ -110,7 +104,7 @@ func (c *ChannelData) Decode() error {
if len(buf) < channelDataHeaderSize {
return io.ErrUnexpectedEOF
}
num := bin.Uint16(buf[0:channelDataNumberSize])
num := bin.Uint16(buf[:channelDataNumberSize])
c.Number = ChannelNumber(num)
l := bin.Uint16(buf[channelDataNumberSize:channelDataHeaderSize])
c.Data = buf[channelDataHeaderSize:]
Expand Down
14 changes: 14 additions & 0 deletions chandata_test.go
Expand Up @@ -263,6 +263,20 @@ func TestChromeChannelData(t *testing.T) {
if err := m.Decode(); err != nil {
t.Errorf("Packet %d: %v", i, err)
}
encoded := &ChannelData{
Data: m.Data,
Number: m.Number,
}
encoded.Encode()
decoded := new(ChannelData)
decoded.Raw = encoded.Raw
if err := decoded.Decode(); err != nil {
t.Error(err)
}
if !decoded.Equal(m) {
t.Error("should be equal")
}

messages = append(messages, m)
}
if len(messages) != 2 {
Expand Down

0 comments on commit 23c404c

Please sign in to comment.