Skip to content

Commit

Permalink
bytes -> bits typo
Browse files Browse the repository at this point in the history
  • Loading branch information
mateusz834 committed Aug 28, 2023
1 parent 91a2552 commit eb23195
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions dns/dnsmessage/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -2000,15 +2000,15 @@ func (n *Name) pack(msg []byte, compression map[string]int, compressionOff int)
}

// Miss. Add the suffix to the compression table if the
// offset can be stored in the available 14 bytes.
// offset can be stored in the available 14 bits.
newPtr := len(msg) - compressionOff
if newPtr <= int(^uint16(0)>>2) {
if nameAsStr == "" {
// allocate n.Data on the heap once, to avoid allocating it
// multiple times (for next labels).
nameAsStr = string(n.Data[:n.Length])
}
compression[string(n.Data[i:])] = newPtr
compression[nameAsStr[i:]] = newPtr
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions dns/dnsmessage/message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1820,20 +1820,24 @@ func TestBuilderNameCompressionWithNonZeroedName(t *testing.T) {
if err := b.StartQuestions(); err != nil {
t.Fatalf("b.StartQuestions() unexpected error: %v", err)
}

name := MustNewName("go.dev.")
if err := b.Question(Question{Name: name}); err != nil {
t.Fatalf("b.Question() unexpected error: %v", err)
}

// Character that is not part of the name (name.Data[:name.Length]),
// shouldn't affect the compression algorithm.
name.Data[name.Length] = '1'
if err := b.Question(Question{Name: name}); err != nil {
t.Fatalf("b.Question() unexpected error: %v", err)
}

msg, err := b.Finish()
if err != nil {
t.Fatalf("b.Finish() unexpected error: %v", err)
}

expect := []byte{
0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, // header
2, 'g', 'o', 3, 'd', 'e', 'v', 0, 0, 0, 0, 0, // question 1
Expand Down

This file was deleted.

This file was deleted.

0 comments on commit eb23195

Please sign in to comment.